Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between == and ===

Tags:

swift

In swift there seem to be two equality operators: the double equals (==) and the triple equals (===), what is the difference between the two?

like image 256
Fela Avatar asked Jun 02 '14 20:06

Fela


People also ask

What is the difference between == and === example?

== is used for comparison between two variables irrespective of the datatype of variable. === is used for comparision between two variables but this will check strict type, which means it will check datatype and compare two values.

What does == === mean?

The === operator means "is exactly equal to," matching by both value and data type. The == operator means "is equal to," matching by value only.

What is the difference between double == and triple === equals?

Double Equals ( == ) checks for value equality only. It inherently does type coercion. This means that before checking the values, it converts the types of the variables to match each other. On the other hand, Triple Equals ( === ) does not perform type coercion.

Why would you use === instead of ==?

Use === if you want to compare couple of things in JavaScript, it's called strict equality, it means this will return true if only both type and value are the same, so there wouldn't be any unwanted type correction for you, if you using == , you basically don't care about the type and in many cases you could face ...


1 Answers

!== and === are identity operators and are used to determine if two objects have the same reference.

Swift also provides two identity operators (=== and !==), which you use to test whether two object references both refer to the same object instance.

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l

like image 121
aglasser Avatar answered Sep 22 '22 09:09

aglasser