Evolution of how identifiers are generated in JavaScript

Source: Internet
Author: User

This paper records the evolution of the method of generating identifiers in JS, from ES5 to ES6,ES5 and before it is a way, which contains only two declarations (var/function), and ES6 adds some keywords that generate an identifier, such as Let, Const, class.

First, ES5 era
    1. Var
    2. function

We know that JS is not like other languages Java, Ruby, and so on, it is used to name variables of the only keyword Var, no matter what type of data are declared with Var, of course, the weak type does not mean that the language does not have a type, its type at run time (according to different operators) will be implicitly converted. In other languages such as Java, the keywords for the light declaration number are int, float, double, long.

Jsvar num1 = ten;      Integer var num2 = 10.1;   Floating-point var str      = ' John ';//string var boo     = false;  boolean var obj      = {};    Object

Javaint num1      = 10;double num2   = 10.2; String str      = "John"; Boolean Boo  = false;

JS identifier In addition to the use of VAR generated, there is also a function keyword can also produce identifiers. The identifier of a function type declaration may be a functional, method, or constructor (class).

Functionsfunction fetchdata (URL, param) {    //...  } Methodsvar obj = {    geturl:function () {    }};//classfunction person (name, age) {}person.prototype = {}

Ii. the era of ES6
    1. Var
    2. function
    3. Let
    4. Const
    5. Class

As you can see, ES6 adds 3 keyword let/const/class that can generate identifiers. Let/const is used to declare variables, class is used to define classes.

Define the normal variable let name = ' John ', for (let i = 0; i < arr.length; i++) {}if (boo) {let    obj = {};    ...} Defines a const PI = 3.1415926;const $el = $ ('. Nav ');//Defines a class of type ' point ' {constructor (x, y) {this.x = x;    This.y = y;}  ToString () {    return ' (' +this.x+ ', ' +this.y+ ') ';  }}

In the ES6 era, we can imagine that our code style should be " less var and morelet", with both allow and const have block-level scopes, and no variable promotion occurs. The Declaration class, too, uses class, and the class keyword shares some of the function's tasks.

Iii. the era of ES7

...

Related:

Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/let

Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/const

Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/class

Evolution of how identifiers are generated in JavaScript

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.