I have seen many places where angular js uses triple equals sign ===
to compare two elements why not 2 equals==
. I am just wondering is there any specific reason for that ?
JavaScript === (Triple Equals) The triple equals sign in JavaScript means “equality without type coersion”. That means, the type and values must both be equal. Take for example the scenario where 0 is false. If we compare the same 0 and false with ===, we have false returned.
Two objects or values are considered equivalent if at least one of the following is true: Both objects or values pass === comparison. Both objects or values are of the same type and all of their properties are equal by comparing them with angular. equals . Both values are NaN.
The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.
Because Typescript ensures that both operands of comparison operator(s) have the same type. When both operands have the same type == and === behave identically.
The ===
operator checks value and type while the ==
operator only checks value, simple example
1 == "1" -> true
1 === "1" -> false (types are not equal)
Sometimes you want to use this strict comparison, especially when checking a boolean value.
1 == true -> true
1 === true -> false (types are not equal)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With