Introduction
In this article we will learn what is the difference between == and === in javascript with example. When we use == and when to use === in javascript.
Previous Updates
In previous articles we have learnt Transaction Commit and Rollback in sql server with example.What is Lock and how to achieve lock on sql table. Authorization in Asp.Net. How high quality content affects your Website. What is Blocking and Deadlock In SQL. Top 30 Asp.net interview question. What is the difference between null and undefined.
Check for null vs undefined in javascript.
JavaScript provides different types of operators. Here, we will be talking about strict equality andType converting equality.
Strict equality (===) means values which we are comparing must have the same type.
This means "2" will not be equal to 2 ("2"===2 it will return false)
Type converting equality (==) means automatically it will covert the variable to value irrespective of data type; either it is a string or a number. This means "2" will be equal to 2 ("2" == 2 it will return true).
So the double equal (==) is an auto type converting equality and three equals (===) is a strict equality operator, i.e., it will not covert values automatically.
EXAMPLE
5== "5" // it will return true because here string will converted as number
5 === "5" // it will return false because here 5 is number and "5" is string
0 comments:
Post a Comment