문제

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)

도움이 되었습니까?

해결책

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."

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top