In this tutorial, We will have a look, at the difference between
This post covers examples and notes about the comparison of
double equal signs(==) and
First, what do equal signs about?
Both operators are used to compare different values.
== is called an
equality operator, which applies type coercion, what doe
type coercion, It converts the values before comparison.
true if m and n are the same
=== is called
identity operators, which do not apply type coercion, not converting the values before conversion.
true, if m and n are the same
strings and the
same reference for
Here are some examples of double equal and three equal operator examples
5 == "5" - true; 5 === "5" - false; "0" == undefined; // true "0" === undefined; // false null == undefined; // true null === undefined; // false
In the above examples,
5==“5”, Comparing number and string, and converted to the same type, i.e numbers, with
== checks value(5==5) and type(numbers) are same, returns true.
5===“5” return false as both operands are different(integer and string)
Both operators are applied to two operands or variables.
|compared two operands or variables, the data type is ignored||compared two operands or variables and data type|
|Returns ||Returns |
|duration||time in milliseconds shown before disappearing from the page|
|type coercion before comparison||type coercion ignored before comparison|