What is the fundamental difference between the use of == and === in Javascript


Please explain why the below code is incorrect when the variables used are Strings.


Why is if(text[i]==myName[0]) incorrect? It is fine, it just doesn't compare data type. Using two equals means data type is not compared. lets say we have this code:

number1 = 1
number2 = "1"

now, number1 == number2 would be true, since both have a value of 1. But number1 === number2 is false, since number1 is integer, and number2 a string.


Thank you for your reply.
What if the data structures under comparison consist of a character array and a string?


No idea, one easy way to find out:

test1 = ['hello'];
test2 = 'hello';
if (test1 == test2){
} else {
if (test1 === test2){
} else {

as long as data type doesn't matter (==), this will return true


Well, what happened was this. I've never seen the === because i used to program in Java, and all of a sudden the editor suggests me to correct the == to ===. I just got a little confused.