What is the difference between == and ===?

What is the difference between equality:

==

and strict equality?

===
+3
source share
4 answers

=== as == except that data types are NOT converted. Thus, the result is true if and only if the expressions and their types are equal.

For instance:

var string1:String = "5"; 
var num:Number = 5; 

Then string1 == numtrue, but string1 === numfalse.

As a result, === is usually considered "more stringent." See: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000686.html

+9
source

. , , . , 1 == true true, 1 === true false, .

+3

==tests for non-equal equality, and ===- tests for strict equality. Strict equality means that the data type of the compared expressions must match.

Here are some examples from the documentation :

s1 = new String("5");
s2 = new String("5");
s3 = new String("Hello");
n  = new Number(5);
b = new Boolean(true);

s1 == s2; // true
s1 == s3; // false
s1 == n; // true
s1 == b; // false

s1 === s2;  // true
s1 === s3; // false
s1 === n; // false
s1 === b; // false

s1 !== s2; // false
s1 !== s3; // true
s1 !== n; // true
s1 !== b; // true
+2
source

ActionScript Operators

Equality :

== Checks two expressions for equality.

Strict equality :

=== Checks two expressions for equality, but does not perform automatic data conversion.

+2
source

Source: https://habr.com/ru/post/1791582/


All Articles