Wednesday, April 3, 2013

Three Equals in javascript

Three equals in javascript comparision is bit confuising. But the difference is pretty simple. Tripple equal can be referred as "Strict Comparision". For example, we have two variables.
var i = 1; and var j ="1".
IF we comapre these two variables using "==", it will return true, since both are 1. But if compare using "===", it will return false. Tripple equals also checks for type. Since one of these variable is string and other is int, they are not equal when using "===". But double equals, does not chekcs for type.
PS: "===" is not there just for fun. You can choose which one you want to use depending upon your need.

Happy Programming. :)

No comments:

Post a Comment