== and triple equals
Although, apparently, in both equals—double
== and triple
===— there is a difference of only one equal
Double equals compares two values loosely, and it also performs type coercion.
Type coercion means that the two values compared only after converting them into a common type.
Let us take a simple example of
var a = 5; var b = '5'; document.write(a==b); // The answer of a==b -> true
In the above example, variable
a has the type Integer, and variable
b has the type Character/String.
Since we have used the
double equals == in the code, we would get the answer "true." But the common sense says that it is not true, as variable
a has an Integer type and variable
b has the String/Character type.
Now let us look at the
Triple Equals Operator(===).
Triple equals operator
=== follows the strict equality rules unlike Double Equals
true. Otherwise, the answer would be
Let us take the example of
var a = 5; var b = '5'; document.write(a===b); // The answer of a===b -> false
In the above example, the variable
a has the datatype Integer, and the variable
b has the datatype String/Character.
When we use
I hope there will be no confusion now regarding Double equals or Triple equals. That's all for this article!