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,434
  • 9
  • 39
  • 64

1 Answers1

6

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

Nina Scholz
  • 376,160
  • 25
  • 347
  • 392