) in Javascript does the same as parseInt?

Possible Duplicate:
Using bitwise OR 0 to floor a number

Performs a bitwise OR on two expressions,eg:

console.log(12.22|0) // output --->12

where does the decimal go? it's the same as parseInt function

parseInt(12.22)  // output --->12

how does it work?


parseInt is useful in cases where one is parsing strings such as "12px".

For example:

pasrseInt("12px"); // returns 12

However, this doesn't make any sense with bit-wise OR:

"12px" | 0; // returns 0

Performing a bit-wise OR is more like applying Math.floor() to a number -- bitwise operations work on 32-bit integers in Javascript.

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

上一篇: Javascript是什么

下一篇: )在Javascript中的作用与parseInt相同吗?