Home > Web Front-end > Front-end Q&A > JavaScript does not mean what symbol

JavaScript does not mean what symbol

青灯夜游
Release: 2023-01-07 11:44:25
Original
9480 people have browsed it

The inequality symbols of JavaScript include: 1. "!=" operator, used to compare whether the values ​​of two operands are not equal; 2. "!==" operator, used to compare two operands Check whether the values ​​of the operands are not equal and whether their types are not the same.

JavaScript does not mean what symbol

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

javascript Not equal to operator

Not equal to operator Description
!= (not equal) Compare whether the values ​​of the two operands are not equal
!== (incomplete etc.) Compare whether the values ​​of the two operands are not equal, and also detect whether their types are not the same

In the equality operation, the following should be noted A few questions:

  • If the operand is a Boolean value, it is converted to a numerical value first, where false is converted to 0 and true is converted to 1.

  • If one operand is a string and the other operand is a number, try to convert the string to a number first.

  • If one operand is a string and the other operand is an object, try to convert the object to a string first.

  • If one operand is a number and the other operand is an object, try to convert the object to a number first.

  • If both operands are objects, the reference addresses are compared. If the reference addresses are the same, they are equal; otherwise they are not equal.

Example 1:

console.log("1" == 1);  //返回true。字符串被转换为数字
console.log(true == 1);  //返回true。true被转换为1
console.log(false == 0);  //返回true。false被转换为0
console.log(null != 0);  //返回true
console.log(undefined != 0);  //返回true
console.log(undefined == null);  //返回true
console.log(NaN != "NaN");  //返回true
console.log(NaN ==1);  //返回false
console.log(NaN == NaN);  //返回false
console.log(NaN != NaN);  //返回true
Copy after login

NaN is not equal to any value, including itself. The null and undefined values ​​are equal, but they are different types of data. In equality comparisons, null and undefined are not allowed to be converted to values ​​of other types.

Example 2:

Comparison of two objects. Although the structure is the same, the addresses are different, so they are not equal.

var a = {};
var b = {};
console.log(a !== b);  //返回true
Copy after login

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of JavaScript does not mean what symbol. For more information, please follow other related articles on the PHP Chinese website!

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