Why does this JavaScript work?

前端 未结 4 1364
难免孤独
难免孤独 2021-01-17 08:27

I was looking at the output of some stuff from UglifyJS and happened across some code like the following:

var a = 0;
var b = function () {
    return functio         


        
4条回答
  •  生来不讨喜
    2021-01-17 09:11

    It works due to the comma operator. From the MDN specs:

    The comma operator evaluates both of its operands (from left to right) and returns the value of the second operand.

    Both functions are IFFYs, they are inmediately executed.

提交回复
热议问题