3

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?

Luke
  • 2,274
  • 9
  • 36
  • 60

1 Answers1

6

Convert to integer and apply a bitwise or with 0. Basically a short form of Math.floor().

Nina Scholz
  • 351,820
  • 24
  • 303
  • 358