difference between var keyword and without var
Possible Duplicate:
Difference between using var and not using var in JavaScript
What is the difference between using var keyword in java script & without using it for a variable?
For example:
var x = 14;
And x = 14;
Are these same or when we declare var x, its a local variable & when it doesn't have var keyword, then its global?
Thanks!
If var
keyword is used within a function or other non-global scope then that variable's scope is not global .
If var
keyword is not used before a variable name, then that variable's scope is global .
Variables declared outside a function become GLOBAL, and all scripts and functions on the web page can access it.
Global variables are destroyed when you close the page.
If you declare a variable, without using "var", the variable always becomes GLOBAL.
链接地址: http://www.djcxy.com/p/17354.html上一篇: javascript变量与var和不var之间的区别?
下一篇: var关键字和无var之间的区别