js> (5).toString(2)
101
js> 5.toString(2)
js: "<stdin>", line 53: missing ; before statement
js: 5.toString(2)
js: ..........^
js>
js> (5).toString(2) 101 js> 5.toString(2) js: <stdin>, line 53: missing ; before statement js:
Share
Javascript assumes (bizarrely) that a number followed by a dot means the dot is a decimal point. This is counter-intuitive, but at least it’s reliable.
You have several choices as to how you deal with this:
Stackoverflow’s syntax highlighter shows you that, in #2 and #3, the first dot is considered to be part of the number and the second to be the operator. In #4, we can see that the space tells the parser that the number has ended.