Deqing
Deqing

Reputation: 14632

Variable assignment bitwise or in Javascript

I ran into a code in Javascript like this:

is_enabled = is_enabled | true;

What does it intend to do? To me it seems doing nothing.

Upvotes: 0

Views: 36

Answers (1)

Galen Cook
Galen Cook

Reputation: 124

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. So, is_enabled's value is either it's previous definition, or if it has not been declared, it is true.

Upvotes: 1

Related Questions