Is setting multiple variables in 1 line valid in javascript? (var x=y='value';)

后端 未结 5 1442
春和景丽
春和景丽 2020-12-13 09:17

This is valid in php:

$x=$y=\'value\';

This will in esscence set both $x and $y to \'value\'.

Is this valid in javascript?

5条回答
  •  无人及你
    2020-12-13 10:10

    To prevent the y from becoming a global variable, use the following:

    var x, y = x = 'value';
    

    Apparently the declarations are simply evaluated from left to right.

提交回复
热议问题