it's important to know which operator is used for which operation.
"==" operator compares variable by their values. Where as "===" operator not only checks the value of variable moreover it compares variable by making their type correction.
Following examples will make it simple to understand.
var n = 12; var s = "12"; document.write("n == s returns " + (n==s) +"<br />"); document.write("n === s returns " + (n===s));
OUTPUT: n == s returns true n === s returns false
Since n is of numeric type. and s is string. "==" operator converts both variable into same type then compares. while "===" operator first compares their types then their values.
var n = 0; var b = false; document.write("n == b returns " + (n==b) +"<br />"); document.write("n === b returns " + (n===b));
OUTPUT: n == b returns true n === b returns false
Since n is of numeric type. and b is boolean. "==" operator converts both variable into same type then compares returns true. while "===" operator first compares their types then their values returns false.
If you have any query or question or topic on which, we might have to write an article for your interest or any kind of suggestion regarding this post, Just feel free to write us, by hit add comment button below or contact via Contact Us form.
Your feedback and suggestions will be highly appreciated. Also try to leave comments from your valid verified email account, so that we can respond you quickly.