The Javascript Object is() method determines whether two values are of the same value.
Syntax:
Object.is(value1, value2)
Parameters:
value1: It represents the first value to be compared.
value2: It represents the second value to be compared.
Return:
It returns true if two values are of the same value otherwise returns false.
Two values are considered to same if:
- value1 and value2 are the same exact object
- value1 and value2 are equal strings.
- value1 and value2 are equal numbers.
- value1 and value2 are both undefined, both null, both NaN, both true or both false.
Example:
<!DOCTYPE html> <html> <body> <script> document.write(Object.is(15, 15) + "</br>"); document.write(Object.is("jai", "w3schools")); </script> </body> </html>