Strict Equality (===) Comparison Operator

Summary

Compares two expressions for value and type equality.

Syntax

expression1 === expression2

Parameters

expression1
Any legal expression.
expression2
Any legal expression.

Description

The strict equality operator compares the values and types of two expressions. The strict equality operator returns true if the resulting values and types of the expressions are equal and false otherwise.

This operator is inherited from JavaScript. If your code uses JS++ types only (such as the int type), strict equality may be redundant. This is because the types are already checked by the JS++ type checker at compile time:

1
2
3
4
5
6
import System;
 
int x = 1, y = 1;
 
Console.log(x === y); // Redundant, type is already checked at compile time
Console.log(x == y);  // Has the same meaning for non-external (JS++) types

However, if at least one side of the comparison expression uses JavaScript types (declared with var, function, or external), it is recommended to use the strict equality operator:

1
2
3
4
5
6
import System;
 
int x = 1;
var y = "1";
 
Console.log(x === y); // 'y' has external (JavaScript) type. Use strict equality (===) over regular equality (==).

Examples

Comparing JavaScript Types and Values
1
2
3
4
5
import System;
 
var x = 1, y = 1, z = "1";
Console.log(x === y); // true
Console.log(y === z); // false

See Also

Share

HTML | BBCode | Direct Link