Difference between variable declaration syntaxes in Javascript (including global variables)?

后端 未结 5 1803
梦毁少年i
梦毁少年i 2020-11-22 01:40

Is there any difference between declaring a variable:

var a=0; //1

...this way:

a=0; //2

...or:



        
5条回答
  •  太阳男子
    2020-11-22 02:33

    Keeping it simple :

    a = 0
    

    The code above gives a global scope variable

    var a = 0;
    

    This code will give a variable to be used in the current scope, and under it

    window.a = 0;
    

    This generally is same as the global variable.

提交回复
热议问题