Home > Web Front-end > JS Tutorial > A brief analysis of the difference between '==' and '===' in Javascript_javascript skills

A brief analysis of the difference between '==' and '===' in Javascript_javascript skills

WBOY
Release: 2016-05-16 16:24:52
Original
1070 people have browsed it

When I used JavaScript before, I would often encounter the use of the two symbols == and === to determine whether two variables are equal. However, the difference between these two symbols has not been investigated. Today I encountered the === symbol again, so I decided to check what the difference is between the two.

There are two comparison operators "==" and "===" in Javascript, so what is the difference between them?

1. For basic types such as string and number, there is a difference between == and ===

1) Comparison between different types, == compares "values ​​after conversion to the same type" to see if the "values" are equal. === If the types are different, the result will be unequal
2) Same type comparison, direct "value" comparison, the result is the same

2. For advanced types such as Array and Object, there is no difference between == and ===

When a variable is defined as Arrary and a variable is defined as Object type, but their values ​​are the same, the results of == and === comparisons are the same because it is a "pointer address" comparison

3. There is a difference between basic types and advanced types, == and ===

1) For ==, convert the advanced type into a basic type and perform "value" comparison
2) Because the types are different, the result of === is false

Related labels:
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