javascript (x, y, z) + a 是什么意思

标签 javascript

我刚从 JavaScript 示例中看到一个表达式,如下所示:

  var some = (x, y, z) + a;

这是什么意思?结果是什么?

最佳答案

这是 JavaScript 的 comma operator

x, y, z; // is the same as
x;
y;
z; // this is the last thing returned, so
(x, y, z) === z;

因此,var some = (x, y, z) + a;var some = z + a; 相同,除了 xy 也被评估。

如果您想将内容缩短到一行或需要在第二个内容可用之前评估某些内容,这很有用。

关于javascript (x, y, z) + a 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14371752/

相关文章:

javascript - react 教程 : TypeError: Cannot read property 'props' of undefined

javascript:动态调用嵌套函数

javascript - 如何使用小号将 href 属性抓取到数组中?

javascript - HTML/CSS 广告定位

MyClass.prototype = {} 和 MyClass.prototype.method 之间的 Javascript 区别

javascript - 创建自定义服务时出现函数错误 - Angular.js

javascript - 如何使用 jQuery 将当前的 index.html 正文内容替换为另一个 html 文件?

javascript - Protractor 无法在 element.all 语句内的 while 循环内执行单击操作

javascript - 在 JavaScript 中比较数组中的两个数字以查看它们是否相等

javascript - React 组件事件处理函数未从 Redux Store 接收到最新值