-3

Apparently return can be invoked as a function?

function say() {
   return (
     console.log("Am"),
     console.log("I"),
     console.log("a"),
     console.log("function?")
  );
}

say();

Does this mean that return is a function?

Artemij
  • 159
  • 1
  • 1
  • 9

1 Answers1

3

The keyword "return" is not a function. The documentations says that return is a statement.

The return statement ends function execution and specifies a value to be returned to the function caller.

That means

(
     console.log("Am"),
     console.log("I"),
     console.log("a"),
     console.log("function?")

)

is evaluated as an expression and the result of this expression is returned from the say() function. The parentheses only group the four calls to console.log together. The commas serve to separate the function calls within the expression.

The this expression will return the value returned from the last element in the list, which in this case is console.log("function?"). And the function console.log returns undefined.

So the function say() would return undefined.

ahoffer
  • 5,758
  • 2
  • 31
  • 63