My very fine question is: in JavaScript, what value does the empty statement evaluate to?
This is the empty statement:
;
...and if I evaluate it, I get undefined
.
console.log(eval(';')) // 'undefined'
However, here is another empty statement (after a statement containing a number literal):
1;;
...and yet this appears to evaluate to 1
.
console.log(eval('1;;')) // '1'
Which surprises me.
So, what does the empty statement evaluate to?
I note the spec says the empty statement returns "empty
". I don't know what that means yet.
The spec also says:
When the term “empty” is used as if it was naming a value, it is equivalent to saying “no value of any type”.
So, the empty statement returns "no value of any type". That means it cannot return undefined
(which is a value of type Undefined
). I am unsure how this maps to userland code.