&& in JavaScript

Source: Internet
Author: User

&& There are three ways to understand JavaScript:

1. When the two operands are Boolean,,&& performs a Boolean and (and) operation on two and returns true only if two are true. If one of them is false, it returns false.

X==0&&y==0//Returns True only if X and Y are both 0

2.&& can perform Boolean and (and) operations on truth and false values. If the two operands are true, then a true value is returned, or at least one of the operands is a false value. (False values are: false, null, undefined, 0, -0, Nan, and "", all other values include all objects being true).

3.&& first calculates the operand on the left. If the result is a false value, the whole is a false value, then the value of the left operand is returned.

Left is true: computes the value of the operand to the right and returns it as the result of the entire expression:

var m={x:1};

var p=null;

O&&o.x//1:o is true, so the return value is o.x

P&&p.x//null:p is a false value, so return it without calculating the p.x

This behavior of && is sometimes called a "short circuit".

&& in JavaScript

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.