Home>Article>Web Front-end> How to determine whether two strings are equal in es6
Judgment method: 1. Use the "==" operator to compare whether the values on both sides of the equation are equal. The syntax is "String 1 == String 2"; 2. Use "Object.is() ", syntax "Object.is(String 1, String 2)", if the two strings have the same length and the same characters are arranged in the same order, the two strings are equal.
The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
es6 Determine whether two strings are equal
Method 1: Use the == operator
==
Operator, you can compare whether the values on both sides of the equation are equal
Example: Determine whether two strings are equal
var x = "hello"; var y = "HELLO"; var z = "hello"; console.log(x == y); // 输出: false console.log(x == z); // 输出: true
Method 2: Use the Object.is() method
Object.is() method to determine whether two values are the same value. The two values are equal if the following conditions are met:
are both undefined
are null
are all true or false
are all strings of the same length and the same characters are arranged in the same order
are all the same object ( means that each object has the same reference)
is a number and
is 0
are all -0
are all NaN
or are both non-zero and non-NaN and are the same value
Example: Determine whether two strings are equal
var x = "hello"; var y = "HELLO"; var z = "hello"; console.log(Object.is(x,z)); // 输出: true console.log(Object.is(x,y)); // 输出: false
[Related recommendations:javascript video tutorial、web front end】
The above is the detailed content of How to determine whether two strings are equal in es6. For more information, please follow other related articles on the PHP Chinese website!