逗号在JavaScript中的赋值语句中做了什么? [英] What does a comma do in assignment statements in JavaScript?

查看:427
本文介绍了逗号在JavaScript中的赋值语句中做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一段代码中发现了这一点,我想知道它的作用是什么?将b分配给x ...但是,c 是什么?

I found this in a piece of code and i'm wondering what it does? Assign b to x... but what's with the ,c?

var x = b, c;


推荐答案

这声明了两个变量, x c ,并将值 b 分配给变量 x

That declares two variables, x and c, and assigns value b to variable x.

这相当于更明确的形式 *

This is equivalent to the more explicit form*:

var x = b;
var c;

JavaScript允许每个 var 关键字&ndash进行多次声明;每个新变量用逗号分隔。这是JSLint建议的样式,它指示开发人员使用单个var per函数(来自JSLint的错误消息是将此与前面的'var'语句结合使用。)。

JavaScript allows multiple declarations per var keyword – each new variable is separated by a comma. This is the style suggested by JSLint, which instructs developers to use a single var per function (the error message from JSLint is Combine this with the previous 'var' statement.).

*实际上,由于提升它将被解释为 var x; var c; x = b

这篇关于逗号在JavaScript中的赋值语句中做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆