Global variables declared with var at the global scope in a browser become properties of which object?

Prepare for the CIW Advanced HTML5 and CSS3 Specialist Exam. Study effectively with comprehensive materials, flashcards, and engaging multiple-choice questions. Enhance your expertise and get ready to succeed!

Multiple Choice

Global variables declared with var at the global scope in a browser become properties of which object?

Explanation:
Global variables declared with var at the global scope in a browser become properties of the window object. The window object is the browser’s global container, so a top-level var creates a property on window, accessible as window.myVar and as myVar in the global scope. This behavior is specific to var; top-level let or const do not create properties on window. The other options—document (the DOM), location (the page URL information), and console (the debugging interface)—are separate browser APIs and not where global var declarations attach.

Global variables declared with var at the global scope in a browser become properties of the window object. The window object is the browser’s global container, so a top-level var creates a property on window, accessible as window.myVar and as myVar in the global scope. This behavior is specific to var; top-level let or const do not create properties on window. The other options—document (the DOM), location (the page URL information), and console (the debugging interface)—are separate browser APIs and not where global var declarations attach.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy