Updating a global variable from a function
问题 There is a global variable called numbers. Function one calculates a random number and stores it in mynumber variable. var mynumber; function one (){ var mynumber = Math.floor(Math.random() * 6) + 1; } I need to use it in a separate function as belows. But an error says undefined - that means the value from function one is not updated. function two (){ alert(mynumber); } How to overcome this problem. Is there a way to update the mynumber global variable. 回答1: If you declare a variable with