August 1st, 2010

I was just bitten by this:

    var foo = "2";
    var bar = 2;

    switch (parseInt(foo)) {
        case bar:
            alert("match");
            break;
        default:
            alert("no match");
    }

That code should alert “match” – but take out the parseInt, and you get “no match.”

It looks like the switch statement uses type checking (i.e. ===, not ==) in FireFox 3.6.8 for Mac (haven’t tried other browsers).

April 21st, 2010



Love it.

April 19th, 2010

http://miketaylr.com

« Older Posts

Valid XHTML 1.0 Strict Valid CSS