O'Reilly logo

Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript by David Herman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2. Variable Scope

Scope is like oxygen to a programmer. It’s everywhere. You often don’t even think about it. But when it gets polluted . . . you choke.

The good news is that JavaScript’s core scoping rules are simple, well designed, and incredibly powerful. But there are exceptions. Working effectively with JavaScript requires mastering some basic concepts of variable scope as well as the corner cases that can lead to subtle but nasty problems.

Item 8: Minimize Use of the Global Object

JavaScript makes it easy to create variables in its global namespace. Global variables take less effort to create, since they don’t require any kind of declaration, and they are automatically accessible to all code throughout the program. This convenience makes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required