What is this asm style “x | 0” some javascript programmers are now using?

前端 未结 4 1682
盖世英雄少女心
盖世英雄少女心 2020-12-05 11:28

I\'ve seen some performance critical javascript code, like the one on this project that makes extensive use of bitwise OR operations with 0. Ex:

GameBoyAdvan         


        
4条回答
  •  不思量自难忘°
    2020-12-05 12:17

    | operator is bitwise OR. It's used to do a bit by bit OR operation on two integers.

    The usage here is a shortcut very similar to logical OR || operator to provide default value, with the exception that the result is integer only (as opposed to string...etc)

    address = address | 0;
    

    means "if address is a number, let's use it; otherwise, set it to 0".

提交回复
热议问题