JavaScript: the nitty gritty

This week, reviewing JavaScript was the idea and learning it inside and out was the intention. After watching Douglas Crockford’s video lectures on The JavaScript Programming Language (parts 1, 2, 3, and 4) and Advanced JavaScript (parts 1, 2, and 3) I felt like I’d been reacquainted with an old friend after years of falling out of touch. After watching them I kept asking myself: “Did I learn a lot?“.

I found that while before I knew JavaScript like I knew a car seeing it drive around a parking lot, I knew it now like I’d been the one driving it. Iterating over object properties? Check. How that factors in with inheritance and using hasOwnProperty to eliminate super classes? Woah, never thought about that!

Similarly, a lot of other things I held dear about good ol’ JS were blown out of the water. Expressions in switch statements, that ambiguously implemented VB-style “with” statement, and breaking to labels were all new to me.

Some of the most interesting things I’d found were the traps and best practices of the language. I always knew parseInt would supply a radix if it wasn’t given one, but HOW it would was scary. Rather than default to 10 like I’d assumed, it tries to guess based on the string (“05” has radix 8, “0x05” has radix 16, “5” has radix 10). Good thing I never had supplied a string with a leading 0 or I’d’ve been in trouble.

Variable declaration and scope was another great thing to learn. I knew of implied global and that there was only function scope, but I never realized the ramifications and power of this. Want to declare a variable or group of logic in a function but then use it outside the function? No problem. Want to do it without cluttering the global namespace? Easy still, just return a closure or anonymous function using that variable. Even though the called function has returned control, the location of returned closure/function declaration ties to the variable itself and it can be used.

Closure usage and private function emulation has found its way into my code in the past, but I suspect it’ll be more and more prominent (especially when dealing with wrapper functions/objects for cross browser code!) in future projects. 🙂

Comments

One response to “JavaScript: the nitty gritty”

  1. Cathy Avatar
    Cathy

    Thanks for posting the video links!

Leave a Reply

Discover more from Software by Steven

Subscribe now to keep reading and get access to the full archive.

Continue reading