JavaScript中的单个竖线是什么意思? [英] What does a single vertical bar mean in JavaScript?

查看:1095
本文介绍了JavaScript中的单个竖线是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个表达式在JS中意味着什么?

What does this expression mean in JS?

Value |= this.value


推荐答案

它是二进制OR,就像在C或C ++或Java中一样。在这种情况下,它在其赋值运算符形式中使用,所以

It's binary "OR", just like in C or C++ or Java. In this case, it's used in its assignment operator form, so

value |= this.value

表示 this.value 都转换为32位整数,并执行按位OR运算。如果为10且 this.value 在操作前为3(即 01010 011 二进制)结果为11( 01011 二进制)。

means that this.value and value are both converted to 32-bit integers, and a bitwise OR operation is performed. If value were 10 and this.value were 3 before the operation (that is, 01010 and 011 in binary) the result would be 11 (01011 in binary).

Javascript中的二进制逻辑运算符在Javascript中值得注意,因为工作是在整数值上执行的。

The binary logic operators in Javascript are notable in Javascript because the work is carried out on integer values.

术语逐位可能比二进制更准确。操作作用于数值的每个位,特别是强制转换为带符号的32位整数的数值。结果也是一个带符号的32位整数(根据规范)。

The term "bit-wise" is perhaps more accurate than "binary". The operations act on each bit of a numeric value, specifically the numeric values coerced to signed 32-bit integers. The result is also a signed 32-bit integer (according to the spec).

但是,静止的JavaScript数字始终是64位二进制浮点值。因此,虽然使用32位整数数学计算,但按位运算符的结果以浮点形式存储。这是因为32位整数的范围可以在64位浮点中舒适而精确地拟合。

However, JavaScript numbers "at rest" are always 64-bit binary floating point values. Thus the results of bitwise operators, though computed with 32-bit integer math, are stored in floating point form. That works because the range of 32-bit integers fits comfortably and precisely in a 64-bit float.

这篇关于JavaScript中的单个竖线是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆