Home >Web Front-end >JS Tutorial >js logical operator short circuit simple operation

js logical operator short circuit simple operation

小云云
小云云Original
2018-02-24 14:23:381966browse

There are three logical operators in js: logical NOT!, logical AND &&, and logical OR ||. The so-called short-circuit operation is that when the value of the first operand of && is false, the value of the first operand is returned directly without calculating the second operand;

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

When || When the value of the first operand is true, the value of the first operand is returned directly without calculating the second operand;

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

Related recommendations:

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

Comprehensive understanding of the logical operators of javascript operators

php logical operators

The above is the detailed content of js logical operator short circuit simple operation. 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