//Inside function
function valueAtBit(num, bit) { var s = num.toString(2); return s[s.length - bit]; } undefined valueAtBit(128,8) "1"
//Outside the function
128.toString(2) //对应函数内第一行 VM2471:1 Uncaught SyntaxError: Invalid or unexpected token
Why?
js thinks that the 128. you entered is a decimal, so here comes the problem. Decimal toString must not be the same thing. Then there are two ways, one is to add an extra dot, the other is to complete the decimal, and the third one is to add a bracket.