Thursday, April 18, 2019

JavaScript Equal Operator == vs ===

Javascript has two equality comparison operator - double equals “==” and triple equals “===”.  Both are used to compare equality of two values and most of time both operator returns same result, until both value are not same data type.

Let us first discuss double equals “==” aka loose equality, in loose equality, first it converts into command type and then it compares equality. 
Example : 

var a = 10,
var b = 10
a == b 
// true

Javascript equality table

   Source : https://dorey.github.io/JavaScript-Equality-Table/

Triple equal “===” aka strictly equality, in strict equality, it does not perform any data type conversion, if both values are not same type, it returns false value. 
Example :

var a = 10,
var b = 10
a=== b 
// false

Javascript equality table

Source : https://dorey.github.io/JavaScript-Equality-Table/

In both example, double equal “==”, it first converts the string ‘10’ and number 10 in same common type and then it compares, so it returns True. But in triple equal “===”, it founds both value are different type and it simply returns False

No comments:

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...