

The assignment operator can evaluate to the assigned valueĬhecks the equality of two operands without considering their type.Ĭompares equality of two operands with their types. = is used for comparing two variables, but this operator also checks datatype and compares two values. = in JavaScript is used for comparing two variables, but it ignores the datatype of variable. = in JavaScript is used for assigning values to a variable. Ī = 2, b = 5, calculate c = a + b, and display c:ĭocument.getElementById("demonstration").innerHTML = c The sum of the value of variable “a” and “b” is 7. We are adding and printing their values using a third variable, “c”.

In the below program, there are two variables “a” and “b”. Lastly, If both variable values are numbers, they are considered equal if both are not NaN (Not a Number) and are the same value.If the variable are of the same type, are not numeric, and have the same value, they are considered as equal.If the variable values are of different types, then the values are considered as unequal.


So, when you compare string with a number, JavaScript converts any string to a number. If we write 10=10, ‘a’ = 10 or ‘a’ = ‘a’, it will result in a reference error.ĭouble equals (=) is a comparison operator, which transforms the operands having the same type before comparison. This operator assigns lvalue to rvalue.įor example, Writing a=10 is fine. Equal to (=) is an assignment operator, which sets the variable on the left of the = to the value of the expression that is on its right.
