What is the difference between var x=1 and x = 1 in NodeJs

This question already has an answer here:

  • What is the purpose of the var keyword and when should I use it (or omit it)? 18 answers

  • 'var x = 3' will create a variable within the current scope. Given this is declared in a function, x will not be available outside it, unless explicitly returned.

    'x = 3' will create a variable within the global scope. Thus, any other code can access and alter its value. It's generally a bad practice to use variables in a global scope.

    链接地址: http://www.djcxy.com/p/17362.html

    上一篇: 在javascript中使用/不使用var前缀定义变量

    下一篇: NodeJs中var x = 1和x = 1之间的区别是什么?