JavaScript in && | | The difference

Source: Internet
Author: User

JavaScript in && | | The difference

&& | | When the operator is not on either side of a Boolean type, the system is converted to a Boolean type value for recalculation (an empty string, NULL, 0 will be turned to false), and the result itself will not change.

&& operator Summary: As long as a false to take the value of false, all is true take the back, is false take the front.

<script type= "Text/javascript" >var a = 123 && 234;var b = 0 && 1;var c = 1 && 0;var d = 1 &A mp;& "", var e = "" "&& 1;var f =" "&& 0;var g = 0 &&" "; Console.log (a);        Output result: 234console.log (b);        Output Result: 0console.log (c);        Output result: 0console.log (d);        Output: "" Console.log (e);        Output: "" Console.log (f);        Output: "" Console.log (g);        Output result:0</script>

|| Operator Summary: As long as a value of true takes true, all is true to take the front, all false take the back.

<script type= "Text/javascript" >var a = 123 | | 234;        Output result: 123var b = 0 | | 1;        Output result: 1var c = 1 | | 0;        Output result: 1var D = 1 | | "";        Output: 1var e = "" | | 1;        Output: 1var f = "" | | 0;        Output: 1var g = 0 | | "";        Output: 0console.log (a); Console.log (b); Console.log (c); Console.log (d); Console.log (e); Console.log (f); Console.log ( g);</script>    

The two operators need to be aware that only one side is false and true, and both are false or true.

JavaScript in && | | The difference

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.