Home  >  Article  >  Web Front-end  >  What are the symbols of or in js

What are the symbols of or in js

下次还敢
下次还敢Original
2024-05-01 05:33:12747browse

There are two kinds of "OR" operators in JavaScript: logical OR (||) and bitwise OR (|). Logical OR is used to check whether there is a true value in multiple values. If any one of them is true, the expression is true. Bitwise OR is used to perform binary OR operation bit by bit. If any bit is 1, the result is 1. .

What are the symbols of or in js

The "OR" symbol in JavaScript

In JavaScript, there are two "OR" operators: Logical OR (||) and bitwise OR (|).

Logical OR (||)

  • is used to check whether two or more values ​​in an expression are true.
  • If any of the operands is true, the expression is true.
  • If all operands are false, the expression is false.

Syntax:

<code>expression1 || expression2 || ...</code>

Example:

<code>console.log(true || false); // true
console.log(false || false); // false</code>

bit or (|)

  • is used to perform a bitwise OR operation on the binary bits of two values.
  • For each binary bit, if any bit is 1, the result is 1.
  • If all binary bits are 0, the result is 0.

Grammar:

<code>expression1 | expression2</code>

Example:

<code>console.log(1 | 2); // 3 (二进制 11)
console.log(5 | 10); // 15 (二进制 1111)</code>

The above is the detailed content of What are the symbols of or in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn