Difference between != and !== operator in JavaScript Program


'!=' comparison operator

'!=' operator checks the unequality of two objects without making the type check. It converts the datatype of two operands to one and then compares their value. For example 1 != '1' will results false.

'!==' comparison operator

'!==' operator checks the unequality of two objects with a type check. It does not converts the datatype and makes a typed check.For example 1 !== '1' will results true.

Following example, shows usage of '!=' vs '!==' operators.

Example

<!DOCTYPE html>
<html>
<head>
   <title>Operator Example</title>
</head>
<body>
   <script language="JavaScript">
      console.log(" 1 != '1' " + (1 != '1'));
      console.log(" 1 !== '1' " + (1 !== '1'));
   </script>
</body>
</html>

Output

1 != '1' false
1 !== '1' true

Updated on: 13-Jan-2020

411 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements