What is the meaning of javascript logical operators

WBOY
Release: 2022-03-24 16:48:19
Original
1910 people have browsed it

In JavaScript, logical operators are special symbols that connect statements into more complex statements. Logical operators can be used to represent logical operations such as "negation", "or", and "and"; in JavaScript There are three logical operators: "!", "&&" and "||".

What is the meaning of javascript logical operators

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What is the meaning of javascript logical operators

Logical operators are used to express ideas such as "and", "or", and "unless" in daily communication.

Logical Operators: In formal logic, logical operators or logical connectives connect statements into more complex statements.

For example, suppose there are two logical propositions, namely "It is raining" and "I am in the house". They can be turned into complex propositions: "It rained, and I was in the house" or "It didn't rain," or "If it rained, I was in the house." A new statement or proposition composed of two statements is called a compound statement or compound proposition.

The reason why "AND" and "OR" have two different forms of operators is that their operation priorities are different. Operators are used to perform program code operations and will perform operations on more than one operand item.

Logical operators in JavaScript

First of all, let’s talk about the rules for converting other data types to Boolean types:

null, undefined, 0, NaN, empty string conversion is false, and others are converted to true.

There are three logical operators in JavaScript:

1. Negation!

First convert the data into a Boolean value, and then negate it. The result is true or false

Copy after login

2. Logical AND &&

The logic in js is different from other languages. If the first operand is true (or can be converted to true), the calculation result is the second operand. If the first operand is false, the result is false (short circuit Calculation), the above rules are not followed for some special values.

Copy after login

3. Logical OR ||

If the first operand is not false, the result is the first operands, otherwise the result is the second operand. If the first operand can be converted to true, the result is the first operand

Copy after login

Related recommendations:javascript learning tutorial

The above is the detailed content of What is the meaning of javascript logical operators. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!