问题
I have been looking into asm.js to use for a project recently, and I noticed that very often the asm.js compiled code will end a statement with |0;
, even seemingly redundantly as in the statement i = i|0;
This is not something I have encountered in Javascript code before. What is it for?
EDIT
I don't believe this is duplicate. I know what a bitwise or is. I am specifically asking here why one might use it to or with a 0 before assignment. What purpose does that serve?
回答1:
Convert to integer and apply a bitwise or with 0
. Basically a short form of Math.floor()
.
来源:https://stackoverflow.com/questions/33367264/what-does-0-do-in-javascript