Home > Web Front-end > JS Tutorial > body text

A brief analysis of the difference between 2 equal signs and 3 equal signs in js_Basic knowledge

WBOY
Release: 2016-05-16 17:26:32
Original
1229 people have browsed it

First of all, == equality is equal, === identity is equal.

==, when the value types on both sides are different, type conversion must be performed first and then compared.

===, no type conversion is performed, and different types must not be equal.

The following are respectively explained:

Let’s talk about === first, this is relatively simple. The following rules are used to determine whether two values ​​​​are === equal:

1. If the types are different, [not equal]

2. If both are numeric values ​​and are the same value, then [equal]; (!Exception) is that if at least one of them is NaN, then [not equal]. (To determine whether a value is NaN, you can only use isNaN() to determine)

3. If both are strings and the characters at each position are the same, then [equal]; otherwise [not equal].

4. If both values ​​are true, or both are false, then [equal].

5. If both values ​​refer to the same object or function, then [equal]; otherwise [not equal].

6. If both values ​​are null, or both are undefined, then [equal].

Let’s talk about ==, according to the following rules:

1. If two value types are the same, perform === comparison.

2. If two value types are different, they may be equal. Perform type conversion and comparison according to the following rules:

a. If one is null and the other is undefined, then [equal].

b. If one is a string and the other is a numerical value, convert the string into a numerical value and then compare.

c. If any value is true

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!