The == operator used to compare two values, whether is equal or not.
The === operator used to compare values with the datatype.
The above both operator are compare two values and return true or false result.
Code:-
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
/*
The == (or !=) operator performs an automatic type conversion if needed.
The === (or !==) operator will not perform any conversion.
It compares the value and the type, which could be considered faster than ==.
[10] === 10 // is false
[10] == 10 // is true
'10' == 10 // is true
'10' === 10 // is false
[] == 0 // is true
[] === 0 // is false
'' == false // is true but true == "a" is false
'' === false // is false
*/
function fun1()
{
alert(10 == "10");
}
function fun2()
{
alert(10 === "10");
}
</script>
</head>
<body>
<button onclick="fun1();">10 == "10"</button>
<button onclick="fun2();">10 === "10"</button>
</body>
</html>
Difference between==and===:- JavaScript
Reviewed by
Network security
on
November 13, 2019
Rating:
5
No comments: