Home > Web Front-end > JS Tutorial > body text

About logical operator short circuit analysis

小云云
Release: 2018-02-26 11:13:48
Original
2119 people have browsed it

There are three js logical operators: logical NOT!, logical AND &&, and logical OR ||. The so-called short-circuit operation is, When the value of the first operand of && is false, the value of the first operand is directly returned and the second operand is no longer calculated;

   var bar1 = 0&&c;    console.log('bar1====='+bar1);    //bar1=====0
    var foo1 = 5&&c;    console.log('foo1===='+foo1);    //报c is not defined错误。
Copy after login

When the value of the first operand of || is true, the value of the first operand is returned directly and the second operand is no longer calculated;

var foo = 5||c;console.log('foo===='+foo);//foo====5 不报错var bar = 0||c;console.log('bar===='+bar);//报c is not defined错误。
Copy after login

Related recommendations:

JS logical operator short-circuit simple operation

Detailed explanation of Boolean values, relational operators, and logical operators in JS and Example

Detailed explanation of php array operator, string operator and logical operator examples

The above is the detailed content of About logical operator short circuit analysis. 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
Popular Tutorials
More>
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!