

In the above code snippet we used the simple way of writing program on Not equal to operator in JavaScript. NOTE: The Not equal to operator value can be written as a != 30 or a != "30", both gives the same result.īasic way of using Not equal to operator Other way to write Not equal to operator in JavaScript.ĭocument.getElementById(" myId").innerHTML = c In the above code snippet we have given same values to the variable a and to the not equal operator, so the result give 'false'. In the above code snippet we have given two different values to the variable a and to the not equal operator, so the result gives 'true'.Īssigning same values Assigning 'a' value as 30 and checking the value with '30' in not equal to operator, so the result givesĭocument.getElementById(" myId").innerHTML = ( a != 30) Assigning different values Assigning 'a' value as 30 and checking the value with '10' in not equal to operator, so the result givesĭocument.getElementById(" myId").innerHTML = ( a != 10)

The symbolic representation of Not equal operator in JavaScript is !=. If the value of two operands are not equal it returns true. Not equal is an comparison operator which is used to check the value of two operands are equal or not. ! evaluates to true if the operand is false and vice-versa.In the previous post we learnt the Equal opeartor, from this post we are going to learn the Not equal operator in Comparison Operators. If both operands are false, the result is false.Įxample 11: Logical NOT Operator const a = true, b = false || evaluates to true if either of the operands is true. When comparing a string with a number, JavaScript will convert the string to a number when doing the comparison. Logical NOT: true if the operand is false and vice-versa.Įxample 9: Logical AND Operator const a = true, b = false Ĭonsole.log((c > 2) & (c 2) || (c<2)) // true Logical OR: true if either of the operands/boolean values is true. Logical AND: true if both the operands/boolean values are true, else evaluates to false Logical operators perform logical operations: AND, OR and NOT. <= evaluates to true if the left operand is less than or equal to the right operand. < evaluates to true if the left operand is less than the right operand.Įxample 8: Less than or Equal to Operator const a = 2 >= evaluates to true if the left operand is greater than or equal to the right operand.Įxample 7: Less than Operator const a = 3, b = 2 > evaluates to true if the left operand is greater than the right operand.Įxample 6: Greater than or Equal to Operator const a = 3 It's because their types are different even though they have the same value.Įxample 5: Greater than Operator const a = 3 In the above example, 2 != '2' gives true. It's the complete opposite of strictly equal =. != evaluates to true if the operands are strictly not equal. = evaluates to true if the operands are equal, however, = evaluates to true only if the operands are equal and of the same typeĮxample 4: Strict Not Equal to Operator const a = 2, b = 'hello' And = also checks for the data type while comparing. Here 2 and '2' are the same numbers but the data type is different. = evaluates to true if the operands are equal and of the same type. != evaluates to true if the operands are not equal.Įxample 3: Strict Equal to Operator const a = 2 If you mistakenly use = instead of =, you might get unwanted result.Įxample 2: Not Equal to Operator const a = 3, b = 'hello'


Note: In JavaScript, = is a comparison operator, whereas = is an assignment operator. = evaluates to true if the operands are equal. Not Equal operator takes two operands: left operand and right operand as shown in the following. Less than or equal to: true if the left operand is less than or equal to the right operandĮxample 1: Equal to Operator const a = 5, b = 2, c = 'hello' Less than: true if the left operand is less than the right operand Greater than or equal to: true if the left operand is greater than or equal to the right operand Greater than: true if the left operand is greater than the right operand Like the equality operator, the inequality operator will attempt to. It is the negation of the equality operator so the following two lines will always give the same result: x y (x y) For details of the comparison algorithm, see the page for the equality operator. Strict not equal to: true if the operands are equal but of different type or not equal at all The inequality operator checks whether its operands are not equal. Strict equal to: true if the operands are equal and of the same type Not equal to: true if the operands are not equal
