What does |0 do in Javascript? [duplicate]

泪湿孤枕 提交于 2019-12-12 17:26:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!