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

前端 未结 4 1703
盖世英雄少女心
盖世英雄少女心 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:12

    What it actually does can be seen in this fiddle

    It's probing the variable against integer type in this case and either "flooring" or set it to 0 if not an integer.

    Thus, there's a tremendous differnece to a = a || 0 which would leave a value of 3.2 untouched.

提交回复
热议问题