iteye_6466 2009-08-01 01:16
浏览 180
已采纳

JavaScript | 号起什么作用

| 这个运算符在js里面有什么作用?
[b]问题补充:[/b]
var num = 11/10|0
这个num得到什么,如果按位于的话。呵呵。
还有答案吗?
[b]问题补充:[/b]
可以把2/10|0就原理说一下吗?

  • 写回答

4条回答 默认 最新

  • ljs2342003 2009-08-03 11:00
    关注

    [quote]Bitwise OR (|)

    The | operator performs a Boolean OR operation on each bit of its integer arguments. A bit is set in the result if the corresponding bit is set in one or both of the operands. For example, 9 | 10 evaluates to 11.

    Division (/)

    The / operator divides its first operand by its second. If used with nonnumeric operands, it attempts to convert them to numbers. If you are used to programming languages that distinguish between integer and floating-point numbers, you might expect to get an integer result when you divide one integer by another. In JavaScript, however, all numbers are floating-point, so all division operations have floating-point results: 5/2 evaluates to 2.5, not 2. Division by zero yields positive or negative infinity, while 0/0 evaluates to NaN.[/quote]

    2/10|0,首先计算2/10, 结果为0.2
    然后计算0.2|0, |首先会把0.2转换为整数,去掉小数点后的数字。然后与0做按位于操作。即:
    00000000
    |

    00000000

    00000000

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置