Detailed ES7 new features

ES7, the standard version released in 2016

Compared with ES6, this standard has two new features

Exponentiation operator

Let’s first look at the basic syntax:

1
2
3
4
5
// 9
3 ** 2

// 9
Math.pow(3, 2)

The result of the exponentiation operator is consistent with the pow method in the Math module

The exponentiation operator is also an arithmetic operator, with a syntax similar to +-*/

1
2
3
var a = 4
// 64
a **= 3

includes() method

Array.prototype.includes()

  1. Function
    Find whether a value exists in the array, if it exists, the method returns true, otherwise it returns false

  2. Basic Grammar

    1
    2
    3
    4
    5
    // false note the different types
    [1, 2, 3, 4].includes('3')

    // true
    ['1', '2', '3'].includes('3')
  3. Parameter description
    includes(target, index) accepts two parameters
    target: the target value to find
    index: the actual subscript index of the search

    1
    2
    // false
    ['a','b','c'].includes('b', 2)
  4. Comparison with indexOf() in ES6
    There is a certain degree of equivalence in function, and both are compared by judging the identity ===
    But there is a difference in the search for NaN

    1
    2
    3
    4
    5
    // -1
    [1, NaN, 2].indexOf(NaN)

    // true
    [1, NaN, 2].includes(NaN)

The indexOf search failed, but includes can be judged to exist, it should be compatible with NaN

Persist in original technology sharing, your support will encourage me to continue to create!