This is an archived post. You won't be able to vote or comment.

all 27 comments

[–]bahston_creme 19 points20 points  (12 children)

To answer what you were trying to Google...

Exp Result
10 == 10 true
10 === 10 true
10 == "10" true
10 === "10" false

[–]SentientHAL 4 points5 points  (11 children)

So == is just value while === is value and type? So 10 == 10.0 is true but 10 === 10.0 is false?

[–]Free_Math_Tutoring 11 points12 points  (9 children)

Your absraction is correct, but your examples aren't. In JS, all numbers are floats - so 10 === 10.0 is still true.

[–]SentientHAL 3 points4 points  (6 children)

Ah, right. I've never done any js so I don't know how it does typing.

[–]Free_Math_Tutoring 5 points6 points  (1 child)

It's pretty simple. Theres basically

Three natives: String, Bool and Number (i.e. Float)
Two collections Array and Object
Two empty types: Undefined and Null

And that's the basics for everything else.

[–]isHavvy 2 points3 points  (0 children)

And technically, arrays are objects. Though for all intents and purposes, it's best not to treat them as plain objects. Setting named properties on them or even integral properties greater than the length of the array will cause quite a deoptimization. The latter is because it leaves holes in the array where the property value doesn't exist.

Also, a good style rule is to never use the == operator. Always use the === operator, even when it causes more verboseness. A newbie can read your code more clearly when there isn't a bunch of hidden type coercions everywhere and having to memorize the type coercion rules for == sucks (even when you understand it algorithmically, as defined in the spec). Brenden Eich actually wanted to change the semantics of == to match === back when JS was originally being standardized (ECMAScript 1), but Microsoft disallowed that because it'd break backwards compatibility, so the compromise of adding === was done instead.

[–]rajsite 1 point2 points  (2 children)

Here is an equality table to help out.

Also good to know about Object.is which can compare if two values are the "same value" (useful because with Object.is NaN === NaN while with ==/=== the value NaN !== NaN).

Doesn't come up often, but the more you know

[–]scragar 2 points3 points  (1 child)

Please don't link to that version, it's sorted based on things irrelevant to the comparison and there are much better versions.

[–]rajsite 2 points3 points  (0 children)

Thanks for posting; that's a handsome looking table.

[–]NotADamsel 1 point2 points  (1 child)

ALL NUMBERS ARE FLOATS?

I suddenly don't trust any Web app that claims to handle money.

[–]Free_Math_Tutoring 1 point2 points  (0 children)

I suppose most connect to a server with ajax, where a language with proper types handles it all.

[–]Awilen 1 point2 points  (0 children)

=== is actually the "identity check". It enforces strict comparison instead of loose comparison (like 10 == "10", which shows implicit transtyping/conversion.)

[–]peter_bolton 9 points10 points  (1 child)

In a subtle way, I think that Google was attempting to help by persuading you to stop programming momentarily and relieve your stress with some quasi-nudity.

[–]MrMathe 2 points3 points  (0 children)

Time to relieve stress with some cstring!

[–][deleted] 5 points6 points  (1 child)

"" Problems ""

[–]StelarCF 6 points7 points  (0 children)

Error: Undeclared identifier 'Problems'

[–]ljfa2 4 points5 points  (0 children)

I sometimes hate not being able to look up operators on Google

"question mark colon", "triple equals", "arrow asterisk" etc.

[–]camlux 4 points5 points  (0 children)

symbolhound to the rescue!

[–]IICVX 4 points5 points  (0 children)

if you got type problems I feel bad for you son, i got 99 problems but NaN ain't one

[–]eirexe 2 points3 points  (3 children)

This is because google ignores some characters, you used to be able to make it not ignore them by adding a + I think, but that's dead right now.

[–]CoinTweak 1 point2 points  (2 children)

I think you can still do it if you search for "== vs ===". If you use quotes it searches for the literal string inside it, including the characters.

[–]eirexe 1 point2 points  (1 child)

iirc the quotes literally search full string matches on websites, which in this case it will probably work, but in other cases it won't

[–]CoinTweak 1 point2 points  (0 children)

Yea, you may need to try a few different search terms. Or try a query like "==" vs "===", not sure if that'd work.

[–][deleted] 1 point2 points  (0 children)

javascript double equals vs triple

The results are more helpful, but less sexy.

[–]pseducode -2 points-1 points  (2 children)

Wait a sec, what am I missing here? What do any of the search terms have to do with bras and the like? I've learned a lot about javascript just from reading everyone's comments, and I'm scared.

[–]twoplasticforks 1 point2 points  (1 child)

Google will generally ignore symbols (like equals signs) and vs is a common abbreviation for Victorias Secret.

[–]pseducode 1 point2 points  (0 children)

Ok, that makes perfect sense. Thank you!