created by Brian Leroux & Andrew Lunny. sparodically uncurated by David Trejo.

automatic semicolon insertion

mar 27 , 2013

This is another case of an accidental global:

    var a = 1
        b = 1;

        var a = 2
            b = 2;

    console.log(a); // prints 1
    console.log(b); // prints 2

While debugging, one might be looking only at the “b” statements, but the problem is the missing comma after “a”. Since JavaScript has “automatic semicolon insertion” for some statements like “var”, a semicolon gets inserted after “a = 2”, and variable “b” gets declared as a global!


null to bool

mar 25 , 2013
    null == false // false

Okay, we know this. Null doesn't convert to boolean.

Now try this...

    !null // true

Well, this is awkward.


false isnt false

mar 6 , 2013
    true == 'true'     // true
    false == 'false';  // false

This is expected behaviour as == doesn't do value equality, but rather it does numeric value equality1, thus 'false' is truethy, thus equals 1


null, undefined and test

feb 28 , 2013

Checking a variable for one word with one to ten letters lowercase only?

Try this regular expression: /^[a-z]{1,10}$/.test('wakaluba').


Both should obviously fail, but return true. srsly, WTF JS?


parseint radix

feb 22 , 2013
    parseInt('fuck');     // NaN
    parseInt('fuck', 16); // 15

So remember kids, always supply a radix!


Fork me on GitHub