Different between == and === operators in javascript
Dung Do Tien Feb 12 2020 201
I am a beginner in Javascript and I am studying about operators, I am searching on the internet and I see many people use === to compare two variables so I have two questions need to explain:
1. What is different between == and === operators in javascript?
2. Which should I use?
Thanks for all your suggestions
Have 1 answer(s) found.
- 1
When declaring a variable we have two parts they are data type and value
var age = 18; // dataType = number, value = 18
So == operator only compare value and === compare both value and datatype
var age = 18; // dataType = number, value = 18 var myAge = "18"; // dataType = string, value = 18 age == myAge; // True age === myAge // False
Sandeep Kumar Apr 03 2020
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.