JavaScript not equal Comparison Operator | Explained
In programming languages, comparison operators are utilized for comparing two values. Depending on the condition, these operators return a boolean value true/ false. The “not equal” is also a comparison operator that determines whether the two operand values are equal or not. It returns true if the two operand values are not equal.
This tutorial will demonstrate the not equal comparison operator in JavaScript.
JavaScript not-equal Comparison Operator
The “not equal” comparison operator is also known as the “inequality” operator. It is denoted as (!=) which is the combination of two characters, an exclamation sign also called not (!) with an equal sign (=). It is used to verify if the two compared values are equal or not; if the values are equal, it returns “false” as an output, and else gives “true”.
Syntax
Use the following syntax for the not-equal operator:
Here, “a” and “b” are two operands that will be checked to determine whether they are equal or not.
Example 1: Compare Two Strings Using not equal Comparison Operator
Here, we will see whether the two strings “hello” and “Hello” are equal or not using the not equal (!=) operator:
The output displays “true” which signifies that both strings are not equal:
Example 2: Compare Character With Number Using not equal Comparison Operator
Now, we will compare and check if the character “1” and the number “1” are equal or not:
The output displayed “false” as both values are equal:
Example 3: Compare Number With Boolean Using not equal Comparison Operator
In this example, we will determine whether the “true” boolean value is equivalent to the “1”:
It returns “false” as output which indicates “1” represents the “true” boolean value:
Example 4: Compare Number With null Using not equal Comparison Operator
Here, we will compare if “0” is equal to the “null”:
The above-given statement output “true”, which means the specified values are not equal:
We have gathered all the details on the JavaScript not equal comparison operator.
Conclusion
The comparison operator “not equal” is frequently referred to as the “inequality” operator. It is represented by the symbol (!=). When two values are compared, this operator determines if they are equal or not; in the case of equal, it outputs “false”; otherwise, it outputs “true”. In this tutorial, we have demonstrated the not equal comparison operator in JavaScript.
Source: linuxhint.com