Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why 3 equals in AngularJS ? Is there any specific reason?

I have seen many places where angular js uses triple equals sign === to compare two elements why not 2 equalsenter image description here== . I am just wondering is there any specific reason for that ?

like image 767
DeepInJava Avatar asked Nov 05 '14 09:11

DeepInJava


People also ask

Why do we use 3 equals in JavaScript?

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.

What is the meaning of === in angular?

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.

What does === in JS mean?

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.

Why we use === in typescript?

Because Typescript ensures that both operands of comparison operator(s) have the same type. When both operands have the same type == and === behave identically.


1 Answers

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)
like image 55
Barry Avatar answered Oct 16 '22 03:10

Barry