New features of JS article ES6

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.