Attention:
1. In the node environment, the--harmony parameter enables the ES6 new feature, many new features will only take effect under strict mode, so use strict or--use_strict, otherwise harmony is not enabled;
1. Block-level scope (block scope)
// Block Scope function F1 () { console.log ("Outside.") );} (function() { if(false) {
F1 defined within the IF {} function F1 () { console.log ("Inside.") ); } } F1 ();} ());
In ES5:
1. Strict mode: will be error: In strict mode code, functions can is only is declared at the top level or immediately within another FU Nction. (function can only be declared at the outermost layer of glocal scope or function)
2. Non-strict mode: output: "Inside";
In ES6:
1. Strict mode: output: "Outside", (Use Command in node Environment:node--harmony--use_strict 1_blockscope.js, using node 1_blockscope.js --harmony command, Harmony not working)
2. Non-strict mode: output: "Inside", (according to the first article above: Non-strict mode does not enable harmony)
Because the block-level scope appears in ES6, the code above is meaningful in the strict mode of ES6 context;
New features of JS article ES6