代码之家  ›  专栏  ›  技术社区  ›  Alex Mcp

关于逗号赋值的混淆

  •  1
  • Alex Mcp  · 技术社区  · 15 年前

    以下代码背后的逻辑是什么?

    var next, output = null, thisNode;
    

    看起来像是某种凝聚 var foo = bar || baz; 但是我对逗号不太熟悉。

    2 回复  |  直到 10 年前
        1
  •  7
  •   jweber    15 年前

    这只是一种较短的写作方式:

    var next;
    var output = null;
    var thisNode;
    
        2
  •  3
  •   Gabriel McAdams    15 年前

    多个变量声明。

    与此相同:

    var next;
    var output = null;
    var thisNode;
    
    推荐文章