var message = "Hi"; { var message = "Bye"; } console.log(message); //Bye The message inside the block still has impact on the outside. Just remember that something like for, while if ... block, they don't create new scope. function blo…
Fiald case 1: let can work in it's block { let a = 10; var b = 1; } a // ReferenceError: a is not defined. b Case 2: Let has no "Hosting" Problem function do_something() { console.log(foo); // ReferenceError let foo = 2; } function do_something(…
View on GitHub Note: A commonly accepted practice is to use const except in cases of loops and reassignment. However, in this resource I'll be using let in place of var for all ES6 examples. Variable: x Object: obj Array: arr Function: func Parameter…
When the ES6 class shipped back in 2015, a number of additional keywords came with it. Two of these are constructor and super. Both of these are specific to the class keyword and make working with classes manageable. Both are utilized when the new ke…
变量的解构赋值 数组的解构赋值 基本用法 ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring). 以前,为变量赋值,只能直接指定值. let a = 1; let b = 2; let c = 3; ES6允许写成下面这样. let [a, b, c] = [1, 2, 3]; 上面代码表示,可以从数组中提取值,按照对应位置,对变量赋值. 本质上,这种写法属于"模式匹配",只要等号两边的模式相同,左边的变量就会被赋予对应的值.下面是…
Values assigned with let and const are seen everywhere in JavaScript. It's become common to hear them explained like so: "const creates an constant (immutable) binding while bindings created with let can be changed (mutated) without issue." Alth…