
Array.prototype.includes()
Array.prototype.includes()
Exponentiation Operator
求幂运算符
ES2016, officially known as ECMAScript 2016, was finalized in June 2016.
ES2016(正式称为ECMAScript 2016)于2016年6月完成。
Compared to ES2015, ES2016 is a tiny release for JavaScript, containing just two features:
与ES2015相比,ES2016是一个很小JavaScript版本,仅包含两个功能:
This feature introduces a more readable syntax for checking if an array contains an element.
此功能引入了一种更具可读性的语法,用于检查数组是否包含元素。
With ES6 and lower, to check if an array contained an element you had to use indexOf, which checks the index in the array, and returns -1 if the element is not there.
在ES6及更低版本中,要检查数组是否包含元素,必须使用indexOf ,它检查数组中的索引,如果元素不存在,则返回-1 。
Since -1 is evaluated as a true value, you could not do for example
由于-1被评估为真实值,因此您无法执行例如
if (![1,2].indexOf(3)) {console.log('Not found')
} With this feature introduced in ES2016 we can do
借助ES2016中引入的此功能,我们可以
if (![1,2].includes(3)) {console.log('Not found')
} The exponentiation operator ** is the equivalent of Math.pow(), but brought into the language instead of being a library function.
幂运算符**等同于Math.pow() ,但被带入语言而不是库函数。
Math.pow(4, 2) == 4 ** 2 This feature is a nice addition for math intensive JS applications.
该功能是数学密集型JS应用程序的不错的补充。
The ** operator is standardized across many languages including Python, Ruby, MATLAB, Lua, Perl and many others.
**运算符在包括Python,Ruby,MATLAB,Lua,Perl和许多其他语言的多种语言中得到了标准化。
翻译自: /
本文发布于:2024-02-04 05:10:19,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170699809252352.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
| 留言与评论(共有 0 条评论) |