0 ) statement gives an integer in javascript

This question already has an answer here:

  • Using bitwise OR 0 to floor a number 5 answers
  • How does x|0 floor the number in JavaScript? 3 answers

  • The | operator performs bitwise logical OR . It requires its parameters to be integers, so it will convert a string to an integer. So

    ( number | 0 )
    

    is equivalent to:

    ( parseInt(number, 10) | 0 )
    

    Any number or'ed with 0 will return that same number, so that makes it equivalen to:

    parseInt(number, 10)
    

    Well, the single pipe between the number and 0 is bitwise operator that treat their operands as a sequence of 32 bits (zeroes and ones). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#.7c_%28Bitwise_OR%29

    链接地址: http://www.djcxy.com/p/77442.html

    上一篇: 不能理解使用

    下一篇: 0)语句在javascript中给出了一个整数