What type is the ‘return’ keyword?

But what is the actual type of ‘return’ itself.

It doesn’t have a type, it isn’t a value.

Attempting typeof return; will give you Unexpected token return.

So, we can pass comma separated expressions into the return statement. Is this a function?

No, while parenthesis can be used to call a function, here they are a grouping operator containing a couple of expressions seperated by a comma operator.

A more useful demonstration would be:

function add(a, b) {
  return (
    (a + b),
    (a - b)
  );
}

console.log(add(2, 2));

Which outputs 0 because the result of a + b is ignored (it is on the LHS of the comma operator) and a - b is returned.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)