Javascript tricks. Why (a, b, c) => 5

.

var a,b,c = function() { return 5; };

Variables a and b are undefined, c is a function, so when we do this (a, b, c) (), do we have 5?

+3
source share
3 answers

The announcement is the same as:

var a;
var b;
var c = function() { return 5; };

or almost the same as:

var a;
var b;
function c() { return 5; };

Using (a,b,c)has nothing to do with the declaration, it just returns the last operand, so (a,b,c)()it’s exactly the same as c()(so far, evaluating a and b has no side effects).

+5
source

Because it (a,b,c)matters c.

See the comma statement . It works similarly in C, C ++.

+10
source

:

var f = function(a,b,c){
    return a, b, {x:a+b, y:a+c}
}

f(1,2,3) {x:3, y:4}, , (a,b,c) c.

0

Source: https://habr.com/ru/post/1730986/


All Articles