Stay One Step Ahead

The traps we saw have been part of JavaScript for a long time. Even though the language has evolved considerably, these gotchas are inherent and they’re here to stay. Thankfully, we can make a preemptive strike to avert these issues using some tools and techniques.

Apply the use strict Directive

Placing ’use strict’; at the beginning of a JavaScript source file or within a function turns on the strict mode of execution. In this mode, the execution runtime does not tolerate, among other things, use of undeclared variables.

If the directive is placed at the top of a script, then all code in the script runs in the strict mode. If placed only within a function, then only the code within that function runs in the strict mode—the ...

Get Rediscovering JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.