javascript 逗号_JavaScript中逗号的奇怪用法

javascript 逗号

I recently discovered a curious yet possibly useful thing in JavaScript, related to the comma operator.

最近,我在JavaScript中发现了一个与逗号运算符有关的奇怪但可能有用的东西。

I mostly use commas to separate properties in an object, or array items.

我通常使用逗号分隔对象或数组项中的属性。

However I never gave much attention the usage of it inside an expression.

但是,我从未在表达式中使用它。

Take this:

拿着这个:

('a', 'b')

Both expressions (in this case strings) are evaluated, and this returns the last element, the expression after the last comma. In this example it returns 'b'.

这两个表达式(在本例中为字符串)均被求值,这将返回最后一个元素,即最后一个逗号之后的表达式。 在此示例中,它返回'b'

You can assign the value to a variable, like this:

您可以将值分配给变量,如下所示:

const letter = ('a', 'b')
letter === 'b' //true

翻译自: https://flaviocopes.com/javascript-commas/

javascript 逗号

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值