ES7
版本记录
版本介绍
This ECMAScript specification is the first ECMAScript edition released under Ecma TC39's new yearly release cadence and open development process. A plain-text source document was built from the ECMAScript 2015 source document to serve as the base for further development entirely on GitHub. Over the year of this standard's development, hundreds of pull requests and issues were filed representing thousands of bug fixes, editorial fixes and other improvements. Additionally, numerous software tools were developed to aid in this effort including Ecmarkup, Ecmarkdown, and Grammarkdown. This specification also includes support for a new `exponentiation operator` and adds a new method to `Array.prototype` called `includes`.
英文
中文
版本概要
版本特性
Array.prototype.includes
includes()
方法用来判断一个数组是否包含一个指定的值,根据情况,如果包含则返回 true
,否则返回 false
。
js
const array1 = [1, 2, 3]
console.log(array1.includes(2))
// Expected output: true
const pets = ['cat', 'dog', 'bat']
console.log(pets.includes('cat'))
// Expected output: true
console.log(pets.includes('at'))
// Expected output: false
语法
Array.prototype.includes(searchElement[, fromIndex])
幂运算符 (**
)
幂(**)运算符
返回第一个操作数取第二个操作数的幂的结果。它等价于 Math.pow()
,不同之处在于,它还接受 BigInt
作为操作数。
js
console.log(3 ** 4) // 3 * 3 * 3 * 3
// Expected output: 81
console.log(Math.pow(3, 4)) // 3 * 3 * 3 * 3
// Expected output: 81
console.log(10 ** -2)
// Expected output: 0.01
console.log(2 ** (3 ** 2))
// Expected output: 512
console.log((2 ** 3) ** 2)
// Expected output: 64