ES2016 "ES7" credit
See the ES2016 standard for full specification of the ECMAScript 2016 language.
ES2016 includes the following new features:
This one is a bit like indexOf
and very useful to the language by relying on returning true or false, not 0
.
arr.includes(searchEl[, fromIndex])
- @searchElement: the element to search for
- @fromIndex: pos in array at which to begin searching
- returns: Boolean
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
A shorthand method to exponetiation has been introduced in JavaScript:
operand
**operand
basic examples
Math.pow(5, 2)
// ...is now
5 ** 2
// 5 ** 2 === 5 * 5