Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Can anyone explain in a simpler term what is the difference of == operator to === in JavaScript in particular. Does it have a change when we compare any data type?
 

Ramiro

Now with an army of Mecha-Ralphs!
Veteran
Joined
Aug 5, 2015
Messages
858
Reaction score
365
First Language
Spanish
It's rather easy.

== is called unrestricted comparison, it checks equality without considering the types, for example, any falsy value will be considered equal with ==,

So then,

null == false, 0 == false, '23' == 23 (yes even strings are considered equal to numbers in js), and so on...

=== is == with a type check, so it must be truly equal to be considered ===, so '23' === 23 is false, and null === 0 is false too.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Ohhh now I understand. I keep using ==, and perhaps the flaw when I do something. That's weird then, I thought the == in Java would be the same in JS, as its a scripting language based from it.

Thanks a lot for solving, a new knowledge learned.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,607
Reaction score
3,883
First Language
Java's Crypt
Primarily Uses
RMMZ
You should always use === when comparing against 0, null, undefined, false and true. Those are values that can easily cause problems when you compare them using ==.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
36,734
Reaction score
9,884
First Language
German
Primarily Uses
RMMV
in Java would be the same in JS, as its a scripting language based from it.
That is where you went wrong - javascript has absolutely nothing to do with java and was never based on it.
Or as someone once said: java is to javascript what ham is to hamster.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,607
Reaction score
3,883
First Language
Java's Crypt
Primarily Uses
RMMZ
That is where you went wrong - javascript has absolutely nothing to do with java and was never based on it.

Or as someone once said: java is to javascript what ham is to hamster.
That's not a bad assumption to make, though. It would be true for basically any language other than Javascript and PHP.
 
Last edited by a moderator:

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
I had the assumption because I thought the reason why it is 'Java'Script is because the syntax and logic flow is the same as of Java. If it was not based on Java, I wonder why, I think the developer could just have used another name for it.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,607
Reaction score
3,883
First Language
Java's Crypt
Primarily Uses
RMMZ
I had the assumption because I thought the reason why it is 'Java'Script is because the syntax and logic flow is the same as of Java. If it was not based on Java, I wonder why, I think the developer could just have used another name for it.
They changed the name to Javascript to try and get popularity over the Java name.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Oh wow, I see. Nice tactic XD
 

Ramiro

Now with an army of Mecha-Ralphs!
Veteran
Joined
Aug 5, 2015
Messages
858
Reaction score
365
First Language
Spanish
Well with ES6 it may have be more based on java than before, but javascript isn't based in syntax by java, it's closer to c and older languages from the '80s with the whole idea of not having data types.

Also they had a prototype based approach and not a class based approach like java.

Yes they named it JS because java was popular and they wanted to leech from that popularity...

Still JS and java are really different on many terms, but any javascript programmer actually knows than having == is practically useless, but they can't remove that for compatibility reasons...
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,812
Reaction score
893
First Language
German
Primarily Uses
RMMZ
The "==" operator in Java only works for simple data types (int, long, boolean, ...) or autopackaged classes (Integer, Long, Boolean, ...). For everything else, it will compare the actual memory storage of the objects you are comparing.
 
Last edited by a moderator:

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
tripple equals checks type as well as value
 

Latest Threads

Latest Posts

Latest Profile Posts

I remade/fixed my Elf XP Mack Templates. The Ears are looking better now.
Male Update.pngFemale Update.png
You can check them out, they are in 12 recolours, both Human and Elf Versions!
I'M BACK BABEY!!!
College is hitting me a lil' softer than I expected, so I'm back on MV!
And to kick things off, here's a lil' test of a tileset edit I made today! (Took me, like, 5 hours, considering this was the first time I've EVER used GraphicsGale...)Edit test SUCCESS.PNG
Red_1,png.PNG
I don't know when I'll have time to finish this, so I'll post this mostly complete version now. Another major character of my project, his name is Red (at least until I can think up a better R-name). In case he looks familiar, it's because his design (and personality) is based directly from my favorite anime character of all time (who is, unfortunately, fairly obscure).

Forum statistics

Threads
124,593
Messages
1,164,638
Members
163,420
Latest member
FreddChan
Top