JavaScript Tips and Tricks
A roundup of ten JavaScript tips and tricks from DevChunks, covering strings, assertions, objects, closures, type conversion, iteration and more.
A roundup of ten JavaScript tips and tricks from DevChunks, covering strings, assertions, objects, closures, type conversion, iteration and more.
How iteration works in JavaScript: the for in loop over object members, traditional for loops over arrays, and the forEach method for cleaner code.
How the JavaScript context object and the this keyword work, how to set the context with function.call, and how execution contexts are created.
How to handle duplicate function names in JavaScript and write polymorphic functions that pick behaviour based on the arguments passed in.
How anonymous functions and closures work in JavaScript, with an example range function that keeps its local variables alive between calls.
How type conversion works in JavaScript and how to implicitly convert objects to numbers, strings or booleans with simple operations.
How the JavaScript Object works as an associative array, how to initialise one, index it, and why keys are always converted to strings.
How to debug JavaScript with the Firebug Firefox plug-in: set breakpoints, step through code, inspect variables and log output with console.log.
The difference between null and undefined in JavaScript, how the delete operator removes properties, and ways to check a variable’s value.
Why string concatenation can hurt JavaScript performance and how Array.join() and string.concat() compare when joining many strings together.
Notes on finding a JavaScript solution for Facebook-style photo tagging, including the now discontinued Photo Notes library.