javascript - What is the difference between a line of code placed inside a function and outside a function?
我想大声告诉你
我想大声告诉你 2017-06-28 09:22:31
0
1
676

//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?

我想大声告诉你
我想大声告诉你

reply all (1)
女神的闺蜜爱上我

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.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!