Skip to content

Latest commit

 

History

History
64 lines (44 loc) · 1.72 KB

ES2016.MD

File metadata and controls

64 lines (44 loc) · 1.72 KB

ES2016 "ES7" credit

See the ES2016 standard for full specification of the ECMAScript 2016 language.

ES2016 includes the following new features:


Array.prototype.includes

This one is a bit like indexOf and very useful to the language by relying on returning true or false, not 0.

Syntax:

  • arr.includes(searchEl[, fromIndex])
  • @searchElement: the element to search for
  • @fromIndex: pos in array at which to begin searching
  • returns: Boolean

Examples:

basic examples

[1, 2, 3].includes(-1)                   // false
[1, 2, 3].includes(1)                    // true
[1, 2, 3].includes(3, 4)                 // false
[1, 2, 3].includes(3, 3)                 // false
[1, 2, NaN].includes(NaN)                // true
['foo', 'bar', 'quux'].includes('foo')   // true
['foo', 'bar', 'quux'].includes('norf')  // false

if fromIndex is greater than or equal to the len of array, false is automatically returned

let arr = ['x', 'y', 'z'];

arr.includes('x', 3)    // false
arr.includes('z', 100)  // false

Exponentiation

A shorthand method to exponetiation has been introduced in JavaScript:

Syntax:

  • operand ** operand

basic examples

Math.pow(5, 2)

// ...is now
5 ** 2
// 5 ** 2 === 5 * 5