function my_function() { var num_num = 1; } $(document).ready(function () { my_function(); alert(num_num); }); In the log writes Uncaught ReferenceError: num_num is not defined . How can I pass the variable num_num to ready(function () ?
function my_function() { var num_num = 1; } $(document).ready(function () { my_function(); alert(num_num); }); In the log writes Uncaught ReferenceError: num_num is not defined . How can I pass the variable num_num to ready(function () ?
var num_num = 0; function my_function() { num_num = 1; } $(document).ready(function () { my_function(); alert(num_num); }); Although the option that Regent offers is more correct:
function my_function() { var num_num = 1; return num_num; } $(document).ready(function () { alert(my_function()); }); var right = -Math.floor((window_width - text_page_1_width) * (23 / 30)); return right; var right = -Math.floor((window_width - text_page_1_width) * (23 / 30)); return right; . In the main function: var new_right = right; alert(new_right); var new_right = right; alert(new_right); . What is wrong here? - Alyoshka LavrushkaDeclare a variable outside the function, not inside.
Source: https://ru.stackoverflow.com/questions/433404/
All Articles
num_numas a result of the function execution? There would be no global variables. - Regent