Home > Web Front-end > JS Tutorial > js logical operators ||_javascript skills

js logical operators ||_javascript skills

WBOY
Release: 2016-05-16 18:26:01
Original
1145 people have browsed it

So check the introduction of js:

1. Logical OR operator ||:

When both operands of operator || are Boolean values, it will Performs a Boolean OR operation.

It first calculates the first operand, and if the value of this expression can be converted to true, then it returns the value of the expression on the left. Otherwise, calculate the second operand

Even if the operand of the || operator is not a Boolean value, it can still be regarded as a Boolean OR operation, because no matter what type the value it returns is, it can be converted is a Boolean value.

On the other hand, || is used for non-Boolean operands, which takes advantage of its feature of returning non-Boolean values. This use of this operator usually selects the first defined and non-null value in a set of alternative values ​​(that is, the first value that will not be converted to false)

Example :

var max=max_width || preferences.max_width || 500

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template