What does (0, eval) () do? [duplicate]


The following is from this question

function q() {
console.log((0, eval)('this'));
}

It returns [Object Window].

What I don't get is the (0,eval) part of this.

What is JS doing with this?

From the link, it says it is indirectly calling eval(). What does indirect mean?

Actually, just see (1,eval)('this') vs eval('this') in JavaScript?, which I've now voted as a duplicate:

.. the Ecma spec considers a reference to eval to be a "direct eval call", but an expression that merely yields eval to be an indirect one -- and indirect eval calls are guaranteed to execute in global scope.

(While the following is [mostly] true, it is not specific to eval usage.)


The comma operator evaluates all the expressions and yields the value of the last expression.

That is, (0, eval) evaluates to eval (which is a function-object value), such that the resulting expression is equivalent to eval('this').

To see it another way:

var f = (0, eval)
f === eval // true
f('this')