简体   繁体   English

按位或Java变量分配

[英]Variable assignment bitwise or in Javascript

I ran into a code in Javascript like this: 我遇到了这样的Javascript代码:

is_enabled = is_enabled | true;

What does it intend to do? 它打算做什么? To me it seems doing nothing. 对我来说似乎什么也没做。

I think the code you are referring to is: 我认为您所引用的代码是:

is_enabled = is_enabled || true

This allows the variable is_enabled to be defined elsewhere in the code. 这样就可以在代码的其他位置定义变量is_enabled So, is_enabled 's value is either it's previous definition, or if it has not been declared, it is true . 因此, is_enabled的值为它的先前定义,或者如果尚未声明,则为true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM