Vra

Why doing this

123.toString()

gives an error...

but this

(123).toString()

Works OK

if possible and "at low level" answer (JIT/Interpreter parsing tokens decisions)

Was dit nuttig?

Oplossing

The JavaScript interpreter considers the . to be a decimal point, and therefore does not expect an alphabet character to follow it, hence the "unexpected token" error. Putting 123 in parentheses tells the interpreter, "run toString() on this object."

Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top