[This post is part of a series on JavaScript quirks.]
Let’s start with a simple rule: the normal equality operators == and != are so problematic that you should always use strict equality (=== and !==). Some people say that there are exceptions to this rule, I disagree [2]. Keeping this rule in mind, we can now take a look at what is strange about ==, without burdening our minds unnecessarily.
[This post is part of a series on JavaScript quirks.]
Most programming languages have only one value for “no value” or “empty reference”. For example, that value is null in Java. JavaScript has two of those special values: undefined and null. They are basically the same (something that will change with ECMAScript 6, as will be explained in the last post of this series), but they are used slightly differently.
A core of JavaScript (the so-called “good parts”) is elegant, but that core is often obscured by quirks. This introduction is the first of a series of blog posts that looks at twelve common quirks and how to best deal with them:
[This post is part of a series on JavaScript quirks.]
JavaScript is very tolerant when it comes to accepting values. For example, everywhere it expects a number, it does not reject values from other types, but tries to convert them:
> '5' - '2'
3
> '5' * '2'
10
Automatic conversion to boolean is rarely problematic and often useful. It is covered here as a preparation for later – we’ll use it to work around quirks. Automatic conversion to string, however, can cause problems.
With Blink, Google has created a permanent fork of the WebKit HTML engine. This blog post mentions a few interesting facts that provide context for that decision.
JavaScript usually automatically converts values to the type that a method or operator needs, which can lead to a variety of bugs. As a counter-measure, Brian McKenna (@puffnfresh) suggests using the following code for your tests:
Object.prototype.valueOf = function () {
throw new Error('Use an explicit toString');
};
Quick tip (via David Klassen): The following shell command lists all (highly experimental!) ECMAScript Harmony [1] features that can be switched on in Node.js.
Most people know that ECMAScript is the language standard behind JavaScript [1]. Fewer people know that its name comes from Ecma International, the organization managing this standard. Interestingly, that organization started as “European Computer Manufacturers Association (ECMA)”, but renamed itself to “Ecma International” in 1994. That was done to reflect its increasingly international focus. Ecma is now not considered an acronym, any more. Ecma International is located in Geneva. In contrast, TC39 [1], the Ecma-hosted committee evolving ECMAScript, is rather USA-centric (true to where JavaScript was created and who created it) and usually meets somewhere in California.
2013-12-23: A new blog post on ParallelJS (as Parallel JS is now called) supersedes this post.
Parallel JS will soon be included in Firefox Nightly builds. This project was initially called River Trail [1]. It automatically parallelizes code that uses the ParallelArray type and its array-like methods (map() etc.). [Source of this post: “Parallel JS lands” by Nicholas D. Matsakis.]