Basic knowledge of javascript equal sign Operator

Source: Internet
Author: User
We can see this line of code if (typeofitem & quot; string & quot;). We can see three equal signs that have never been written before, maybe it's because my JS technology is still in its infancy, I checked some materials on the Internet and said that this is a fully equal sign. I used to use the equal sign "=" and never used the fully equal sign "=" in JS ". When the two operators only detect the equality of two objects, one executes the type conversion and the other does not convert. All equal to the symbol returns true only when the type is not converted.

The Code is as follows:


Var sNum = "66 ";
Var iNum = 66;
Alert (sNum = iNum); // The output is true.
Alert (sNum === iNum); // The output is false.


When the first equals operator is compared, the sNum value "66" is converted to the numeric type, and then compared with the iNum, true is returned.
The second full equal sign comparison does not perform type conversion, so the string and number types cannot be true, and all return false
There is also a non-full equal sign and non-equal

The Code is as follows:


Var sNum = "66 ";
Var iNum = 66;
Alert (sNum! = INum); // the return value is false.
Alert (sNum! === INum); // return true


The first operator is easy to understand. The operator converts sNum to the numeric type. After converting to the numeric type, the two values are equal and false is returned.
The second operator does not convert the sNum type. Therefore, sNum is not equal to iNum. Therefore, true is returned.
This is my learning notes.

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.