What's the matter with global scope anyway?

In browser based JavaScript every object you create is assigned to the global scope. For the browser, this object is simply known as window. It is simple to see this behavior in action by opening up the development console in your favorite browser.

Tip

Opening the Development Console

Modern browsers have, built into them, some very advanced debugging and auditing tools. To access them there is a menu item, which is located under Tools | Developer Tools in Chrome | Tools | Web Developer in Firefox, and directly under the menu as F12 Developer Tools in Internet Explorer. Keyboard shortcuts also exist for accessing the tools. On Windows and Linux, F12 is standard and, on OSX, Option + Command + I is used. ...

Get Mastering JavaScript Design Patterns - Second Edition 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.