python python - 2 years ago 70
Javascript Question

what's the difference if a number with parenthesis or without parenthesis?

enter image description here

the type of (8) and 8 are both numbers, but when called toString() method, (8) success but 8 failed, why?

Answer Source

The difference between having 8 and (8) is, the former is a plain number and the latter is a JavaScript Expression. The problem with the Exception is, the way you have written:


Here, the 8. is treated as a floating point or decimal, which causes the syntax error. Since it takes it as a decimal, giving a decimal yields the right result:

» 8.0.toString(2);
« "1000"

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download