Parsing a string variable in JavaScript that suddenly turns false

Source: Internet
Author: User

In order to facilitate debugging, wrote a page is not logged in, Debug mode automatic login function, found that there is a variable i initialized to it to assign a string, but in the use of the time to find it turned false, good magic. After careful examination of the reference, it is found that a judgment condition is less than an equal sign. The JS code is as follows:
var ssessionkey = "Test_key";
if (Ssessionkey=Undefined | | Ssessionkey = = null) {
Console.error ("The Ssessionkey is null.");
Return
} console.info (Ssessionkey);//1 finally found that the 1 print will be false, carefully examine the discovery of the judgment ssessionkey less write an equal sign, resulting in an assignment symbol. Then why does it turn false? Speculation is related to the precedence of symbolic operations in JavaScript, and the precedence of the assignment operator is lower than the seek or operator, so the above judgment is equivalent to the following expression: if (Ssessionkey = (undefined | | ssessionkey = = NULL ) {} "Ssessionkey = = NULL" is the false,undefined judgment is also false, so the last assignment to Ssessionkey is a false. The final print is also false.

Parsing a string variable in JavaScript that suddenly turns false

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.