Effect of declared and undeclared variables

后端 未结 4 894
渐次进展
渐次进展 2020-11-28 09:38

What is the major difference between JavaScript declared and undeclared variables, since the delete operator doesn\'t work on declared variables?

 var y = 43         


        
4条回答
  •  清酒与你
    2020-11-28 10:22

    The main difference is when you're declaring variables inside a function. If you use var when you're declaring a variable inside a function, then that variable becomes a local variable. However, if you don't use var, then the variable becomes a global variable no matter where you declare it (inside or outside a function).

提交回复
热议问题