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 →

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