Learn Node.js by Building 6 Projects Chapter 1, A Simple Web Server, will be very basic project. We're going to take the sample code from the Node.js website and expand on that. Chapter 2, A Basic Express Website, will be a basic Express website whe
以往版本的JS中,如果你在if中定义一个变量,这个变量在if外部也是可以访问的,而不管if条件是否被执行,如:
if(false){
var x = “hello JShaman”
}
console.log(x);
执行这段代码不会失败、不会报错,但会输出undefined:
这情况很可能会引起bug,而且很难找出原因。
在ES6(即:ES2015)中,为了解决这个隐患,引入了let关键字。Let定义的变量,只在自身所在的作用域生效果。修改上述代码如下:
if(false){
let x =