Special usage of "| |", "&&" in JavaScript

Source: Internet
Author: User

The special usage of "| |", "&&" in Javscript can make the code simple and Beautiful in the right place.

-----------------------------------------------------

A = 6;

a>=5 && alert (' OK ');

------------------------------------------------------

A = 6;

Alert (a >= 5 && "yes") | | (A < 5 && "no");

----------------------------------------------

Judging from left to right, encounter false returns, if not encountered, returns the last

var a = true && && 45;

alert (a);

var a = True && 0 && ' aaa ';

alert (a);

var a = && && ' aaa ' && true && 0 && 10;

alert (a);

-----------------------------------------------------------

From left to right, look for the first return to true, and return the last one without encountering it.

A = 12 | | False | | 13;

alert (a);

---------------------------------------------------------------

var a = 10;
var b = {' 5 ': 1, ' Ten ': 2, ' ': 3, ': 4}[a] | | 0;

Alert (b)

---------------------------------------------------------

Special usage of "| |", "&&" in JavaScript

Related Article

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.