Basic equal sign operator in javascript

Source: Internet
Author: User

Today, I saw situ's article in my blog. I saw this line of code if (typeof item = "string"). I saw three equal signs that I have never written before, maybe it's the reason why my JS technology is still in its infancy. I went to the Internet and checked some information online, saying that this is a fully equal sign.

In the past, the equal sign "=" has never been used in JS to use the equal symbol "= ". 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.

 

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

 

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.