=== vs ==


#1

I can't find a general JavaScrip questions thread, so I'm posting here. Later in the course they start using == to compare terms, yet early on they teach you to use ===. What is the reason for this? They have both worked, but is one better to use than the other? If not I'll just use == like most of the languages I know.


#2

they work different, === also compares data type, for example:

2 == "2"

would be true, since both are 2, but:

2 === "2"

would be false, both are 2, but the one is a string, the other a integer. Why in this course they made the switch from 3 equals sings to two? Probably because the sections where written individually from each other. The important bit is to understand the difference


#3

That's weird. Why wouldn't they just use == for everything and if you want to compare to different types, convert the type?


#4

that is exactly what you do here? You compare if the type is also the same, otherwise you also have to make a conversion


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.