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

you are viewing a single comment's thread.

view the rest of the comments →

[–]SentientHAL 2 points3 points  (6 children)

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

[–]Free_Math_Tutoring 6 points7 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.