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

Advance your skills with the uCertify CIW – Advanced HTML5 and CSS3 Specialist Test. Study with flashcards and multiple-choice questions, complete with hints and explanations to enhance your learning. Prepare effectively and ace your exam!

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