Javascript quot;tuplequot; notation: what is its point?(Javascript“元组符号:它的意义是什么?)
问题描述
在 wtfjs,我发现以下是合法的javascript.
At wtfjs, I found that the following is legal javascript.
",,," == Array((null,'cool',false,NaN,4)); // true
参数 (null,'cool',false,NaN,4)
对我来说看起来像一个元组,但 javascript 没有元组!
The argument (null,'cool',false,NaN,4)
looks like a tuple to me, but javascript does not have tuples!
我的 javascript 控制台中的一些快速测试会产生以下结果.
Some quick tests in my javascript console yields the following.
var t = (null,'cool',false,NaN,4); // t = 4
(null,'cool',false,NaN,4) === 4; // true
(alert('hello'), 42); // shows the alert and returns 42
它的行为似乎与分号 ;
分隔的语句列表完全一样,只是返回最后一条语句的值.
It appears to behave exactly like a semicolon ;
separated list of statements, simply returning the value of the last statement.
在某处有描述此语法及其语义的参考吗?为什么会存在,即应该在什么时候使用?
Is there a reference somewhere that describes this syntax and its semantics? Why does it exist, i.e. when should it be used?
推荐答案
你看到了 逗号运算符.
逗号运算符计算其两个操作数(从左到右)并返回第二个操作数的值.
The comma operator evaluates both of its operands (from left to right) and returns the value of the second operand.
a,b,c,...,n
求值时的结果值将始终是最右边表达式的值,但是链中的 所有 表达式仍在评估中(从左到右).
The resultant value when a,b,c,...,n
is evaluated will always be the value of the rightmost expression, however all expressions in the chain are still evaluated (from left to right).
这篇关于Javascript“元组"符号:它的意义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Javascript“元组"符号:它的意义是什么?


- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Flexslider 箭头未正确显示 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01