Compare the usage differences between == and ===
1. For basic types such as string and number, there is a difference between == and ===
Sometimes you will see three equal signs (===) used when judging whether two objects are equal. What is the difference between it and two equal signs (==)? Woolen cloth? To put it simply, when using "==", if the types of both sides are different, the js engine will convert them into the same type and then compare them, while "===" will not perform type conversion, so when the two sides do not belong to the same Type, definitely not equal. For example:
var a = 0, b = '0'; alert((a == b) + '--' + (a === b))
The result seen at this time is "true–false".
=== Judgment rules
If the types are different, [not equal]
If both are numerical 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)
If both are strings and the characters at each position are the same, then [equal]; Otherwise [not equal].
If both values are true, or both are false, then [equal].
If two values refer to the same object or function, then [equal]; otherwise [not equal].
If both values are null, or both are undefined, then [equal].
== Judgment rules:
If the two value types are the same, perform === comparison.
If two value types are different, they may be equal. Perform type conversion and then compare according to the following rules:
If one is null and the other is undefined, then [equal].
If one is a string and the other is a numerical value, convert the string into a numerical value and then compare.
If any value is true, convert it to 1 and compare; if any value is false, convert it to 0 and compare.
If one is an object and the other is a numeric value or string, convert the object into a value of the basic type and then compare. The object is converted to the base type using its toString or valueOf method. JS core built-in classes will try valueOf before toString; the exception is Date, which uses toString conversion. Non-js core objects, let's say (it's more troublesome, I don't quite understand)
Any other combination is [not equal].
Special attention needs to be paid to the conversion of true and false, for example:
alert(true == 1); //ture alert(true == 2); //false, true会转换成number,也就是1,当然 1 不等于 2 //可以使用 !! 来把一个数据类型转换为boolean型 alert(true == !!2) //true,!2 === false !(!=2) = !false = true
In addition, in js, if a variable is used in a logical operation, then the variable is When there is no initial value or its value is 0, -0, null, "", false, undefined or NaN, its value is false. Otherwise, its value is true.
The above is the detailed content of Compare the usage differences between == and ===. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The difference between multithreading and asynchronous is that multithreading executes multiple threads at the same time, while asynchronously performs operations without blocking the current thread. Multithreading is used for compute-intensive tasks, while asynchronously is used for user interaction. The advantage of multi-threading is to improve computing performance, while the advantage of asynchronous is to not block UI threads. Choosing multithreading or asynchronous depends on the nature of the task: Computation-intensive tasks use multithreading, tasks that interact with external resources and need to keep UI responsiveness use asynchronous.

There is no built-in sum function in C language, so it needs to be written by yourself. Sum can be achieved by traversing the array and accumulating elements: Loop version: Sum is calculated using for loop and array length. Pointer version: Use pointers to point to array elements, and efficient summing is achieved through self-increment pointers. Dynamically allocate array version: Dynamically allocate arrays and manage memory yourself, ensuring that allocated memory is freed to prevent memory leaks.

The difference between Ethereum and Bitcoin is significant. Technically, Bitcoin uses PoW, and Ether has shifted from PoW to PoS. Trading speed is slow for Bitcoin and Ethereum is fast. In application scenarios, Bitcoin focuses on payment storage, while Ether supports smart contracts and DApps. In terms of issuance, the total amount of Bitcoin is 21 million, and there is no fixed total amount of Ether coins. Each security challenge is available. In terms of market value, Bitcoin ranks first, and the price fluctuations of both are large, but due to different characteristics, the price trend of Ethereum is unique.

In C language, the main difference between char and wchar_t is character encoding: char uses ASCII or extends ASCII, wchar_t uses Unicode; char takes up 1-2 bytes, wchar_t takes up 2-4 bytes; char is suitable for English text, wchar_t is suitable for multilingual text; char is widely supported, wchar_t depends on whether the compiler and operating system support Unicode; char is limited in character range, wchar_t has a larger character range, and special functions are used for arithmetic operations.

The core difference between bean bun and DeepSeek is retrieval accuracy and complexity. 1. Doubao is based on keyword matching, simple and direct, with low cost, but low accuracy, and is only suitable for structured data; 2. DeepSeek is based on deep learning, can understand semantics, has high accuracy, but high cost, and is suitable for unstructured data. The final choice depends on the application scenario and resource limitations. If the accuracy requirements are not high, choose bean bags, and if you pursue high precision, choose DeepSeek.

C language functions are the basis for code modularization and program building. They consist of declarations (function headers) and definitions (function bodies). C language uses values to pass parameters by default, but external variables can also be modified using address pass. Functions can have or have no return value, and the return value type must be consistent with the declaration. Function naming should be clear and easy to understand, using camel or underscore nomenclature. Follow the single responsibility principle and keep the function simplicity to improve maintainability and readability.

The collaborative working mechanism between Apache or Nginx and PHP: Comparison of mod_php5, php-cgi and php-fpm is to use Apache or Nginx to build a web server and use PHP for backend...

Two ways to define structures in Go language: the difference between var and type keywords. When defining structures, Go language often sees two different ways of writing: First...
