Variable scoping and declaration keywords (var, let, and const) determine where identifiers are visible and accessible within a JavaScript execution context. While legacy var relies on function scoping and exhibits hoisting initialized as undefined, modern ES6+ keywords let and const enforce strict block scoping and introduce the Temporal Dead Zone (TDZ) to prevent premature access. Understanding scope chains, lexical environments, and global object attachment behavior is critical for preventing variable leakage, avoiding accidental mutations, and succeeding in technical software engineering interviews.
JavaScript This Keyword & Scope MCQs
1 min read
Correct Answer: b) Function-scoped
Explanation:
Variables declared with 'var' are scoped to the containing function, meaning they are accessible anywhere within that function regardless of block boundaries.
Correct Answer: b) let and const
Explanation:
Both 'let' and 'const' introduce block scoping, limiting variable visibility to the nearest enclosing curly braces.
Correct Answer: b) It is attached as a property of the global window object.
Explanation:
Global 'var' declarations create properties on the global window object in browsers, whereas 'let' and 'const' do not.
Correct Answer: b) The state where let and const variables are hoisted but uninitialized, throwing a ReferenceError if accessed before declaration.
Explanation:
The TDZ refers to the execution phase from the start of a block scope until a 'let' or 'const' variable is fully initialized.
Correct Answer: b) "undefined"
Explanation:
The 'typeof' operator is safe to use on completely undeclared identifiers and returns the string "undefined" without throwing an error.
Correct Answer: a) They are hoisted to the top of their scope and initialized with 'undefined'.
Explanation:
Variables declared with 'var' are hoisted to the top of their enclosing scope and automatically initialized with 'undefined'.
Correct Answer: c) const
Explanation:
The 'const' keyword creates a read-only reference to a value, preventing variable reassignment after initial declaration.
Correct Answer: b) No, const prevents variable reassignment, but object properties can still be modified or mutated.
Explanation:
const restricts reassignment of the variable identifier itself, but the underlying object reference remains mutable.
Correct Answer: a) A hierarchical chain of scope objects used by the JavaScript engine to resolve variable identifiers during lookups
Explanation:
When resolving a variable, JavaScript checks the current scope first and traverses upward through enclosing lexical scopes.
Correct Answer: a) Scope is determined entirely by where variables and blocks are authored in the source code structure at compile time.
Explanation:
JavaScript uses lexical scoping, meaning a function's scope is defined by its physical placement in the source code.
Correct Answer: a) A function bundled together with references to its lexical surrounding environment, allowing it to remember outer variables even after the outer function has returned
Explanation:
Closures combine a function with its lexical environment, enabling state privacy and persistent scope retention.
Correct Answer: b) function
Explanation:
The 'function' keyword is the standard construct for declaring named functions in JavaScript.
Correct Answer: a) They are hoisted along with their complete function body definition, allowing them to be called before their written line.
Explanation:
Function declarations are fully hoisted with their definitions, allowing invocation prior to their declaration in code.
Correct Answer: b) Only the variable identifier is hoisted according to its declaration keyword, not the function assignment itself.
Explanation:
Function expressions behave like regular variable declarations during hoisting, so invoking them early throws an error.
Correct Answer: a) Variables declared at the top level of a module file are local to that module and not automatically added to the global scope.
Explanation:
ES6 modules have their own file-level scope, preventing global namespace pollution.
Correct Answer: a) It prevents accidental global variable creation by throwing an error if an undeclared variable is assigned a value.
Explanation:
Strict mode enforces stricter parsing and error handling, immediately catching silent errors like undeclared variable assignments.
Correct Answer: b) class
Explanation:
'class' is a reserved keyword in JavaScript used for class declarations and will throw a SyntaxError if used as an identifier name.
Correct Answer: a) When a variable declared within an inner scope has the same name as a variable in an outer scope, temporarily masking the outer variable inside the inner block
Explanation:
Variable shadowing occurs when an inner scope identifier takes precedence over an outer scope identifier with the identical name.
Correct Answer: b) No, redeclaring a 'let' variable in the same scope throws a SyntaxError.
Explanation:
The 'let' declaration rules explicitly forbid redeclaring the same variable identifier within the exact same scope block.
Correct Answer: a) Yes, 'var' allows multiple declarations of the same variable name without syntax errors.
Explanation:
'var' permits duplicate declarations in the same scope without syntax errors.
Correct Answer: a) The global object (window in browsers)
Explanation:
In non-strict mode, calling a standard regular function defaults its 'this' binding to the global window object.
Correct Answer: b) undefined
Explanation:
Under strict mode, regular function calls without an explicit execution context leave 'this' as undefined instead of defaulting to the global object.
Correct Answer: b) They lexically bind 'this', inheriting the value from their enclosing surrounding execution scope.
Explanation:
Arrow functions capture 'this' from their surrounding lexical context at definition time rather than creating a new execution binding.
Correct Answer: a) A 'let' declared in the loop head creates a new variable binding for each iteration loop cycle, whereas 'var' shares a single scoped variable.
Explanation:
Using 'let' in loop initializers creates fresh bindings per iteration, solving asynchronous closure callback indexing bugs.
Correct Answer: a) In Node.js, top-level variables are scoped to the module file rather than global objects, unlike browsers where top-level var attaches to window.
Explanation:
Node.js wraps each file in a module function wrapper, meaning top-level declarations are local to that module file.
Correct Answer: b) It returns false (or throws an error in strict mode) because local variables are non-configurable properties.
Explanation:
The delete operator only removes object properties; variable environment bindings are non-configurable and cannot be deleted.
Correct Answer: b) No, declaring a 'const' variable without initialization throws a SyntaxError.
Explanation:
Because constants cannot be reassigned, they must be initialized with a value at the exact moment of their declaration.
Correct Answer: a) Local scope takes precedence, shadowing the outer global variable.
Explanation:
The scope chain resolution inspects scopes from innermost to outermost, stopping at the first match it encounters.
Correct Answer: a) To create a private temporary function scope and prevent polluting the global namespace
Explanation:
Before ES6 block scoping, IIFEs were the primary pattern used to encapsulate variables and protect the global scope.
Correct Answer: a) Function declarations and expressions
Explanation:
Functions create new scopes in JavaScript, whereas traditional 'var' declarations ignore block boundaries like if statements.
Correct Answer: a) It succeeds because inner functions have lexical access to outer scopes via the scope chain.
Explanation:
Lexical scoping allows inner functions to read and write variables in their outer enclosing execution contexts.
Correct Answer: a) They are scoped to the function body scope.
Explanation:
Function parameters act like local variables declared inside the function body scope.
Correct Answer: a) Unintentionally creating global variables by omitting declaration keywords, leading to unpredictable name collisions
Explanation:
Relying on implicit globals pollutes the global scope and makes code fragile.
Correct Answer: a) Lexical scope is determined by code structure at compile time, whereas dynamic scope is determined by the call stack execution order at runtime.
Explanation:
JavaScript is lexically scoped; functions evaluate identifiers based on where they were written, not where they were invoked.
Correct Answer: a) The catch block creates its own local block scope for the error parameter.
Explanation:
In ES6, the error identifier specified in a catch clause is block-scoped to the catch block itself.
Correct Answer: a) A switch statement body shares a single scope; declarations like 'let' or 'const' inside switch cases require explicit block curly braces.
Explanation:
Because a switch block is a single scope, declaring duplicate 'let' variables across cases without inner curly braces throws a SyntaxError.
Correct Answer: a) Reassignment changes the variable reference (forbidden with const), while mutation modifies internal data of the referenced object/array (allowed with const).
Explanation:
const protects against pointer reassignment, not structural mutation of composite reference values.
Correct Answer: a) It maps variable identifiers to their corresponding memory storage locations during evaluation.
Explanation:
Scope objects (Lexical Environments) maintain environment records that map identifier names to values.
Correct Answer: a) Yes, because hoisting brings declarations to the top of the scope before execution begins.
Explanation:
Hoisting ensures declarations are processed before code execution begins.
Correct Answer: a) It throws a ReferenceError because 'let' is block-scoped.
Explanation:
Block-scoped variables cease to exist outside their defining curly braces.
Correct Answer: a) An issue where two variables share the same identifier name in overlapping scopes, causing shadowing or errors
Explanation:
Name collisions occur when identifier names overlap, which can lead to unintended variable shadowing.
Correct Answer: a) let and const
Explanation:
Modern JavaScript practices recommend replacing 'var' with 'let' and 'const' to ensure predictable block scoping.
Correct Answer: a) An abstract environment that holds information about code evaluation, including variable environments, scope chains, and the 'this' value
Explanation:
Execution contexts manage the lifecycle, scope, and evaluation of code.
Correct Answer: a) The callback retains access to its original lexical scope via closure, even when executed later after outer functions have returned.
Explanation:
Closures ensure asynchronous callbacks remember the exact lexical environment where they were created.
Correct Answer: a) Function-scoped or globally-scoped, leaking outside the catch block
Explanation:
Before ES6 block scoping, 'var' declarations leaked outside catch blocks and loops into enclosing functions.
Correct Answer: a) No, it throws a ReferenceError because it resides in the Temporal Dead Zone.
Explanation:
Accessing 'let' or 'const' variables prior to their declaration line triggers a ReferenceError due to the TDZ.
Correct Answer: a) Global scope encompasses all global variables and lexical declarations, while the window object represents the global browser execution context window.
Explanation:
While 'var' globals become properties of 'window', lexical declarations reside in the global declarative environment record.
Correct Answer: a) It prevents unintended variable overwrites, reduces name collisions, and avoids tight coupling across independent modules.
Explanation:
Keeping scopes localized and modular prevents bugs caused by accidental global state modification.
Correct Answer: a) It is local to the nested function and cannot be accessed by outer enclosing functions.
Explanation:
Inner scopes can look outward, but outer scopes cannot look inward into nested function scopes.
Correct Answer: a) A component of lexical environments that binds variables, constants, and functions directly
Explanation:
Declarative environment records manage identifier bindings for block-scoped declarations like let and const.
Correct Answer: a) It throws a SyntaxError immediately during parsing.
Explanation:
Strict mode prevents duplicate parameter names in function definitions to eliminate ambiguity.
Correct Answer: a) An environment record associated with a global object, binding global variables and properties
Explanation:
Object environment records tie global object properties (like window properties) directly to identifier bindings.
Correct Answer: a) Generator functions maintain their own lexical environment and scope chain just like regular functions.
Explanation:
Generators preserve execution contexts and scopes across yields and resumptions.
Correct Answer: a) No, they remain in the Temporal Dead Zone until their declaration line is evaluated.
Explanation:
Block-scoped variables are hoisted without initialization, remaining in the TDZ until execution reaches the declaration.
Correct Answer: a) Function scope encloses variables across the entire function body (var), whereas block scope restricts variables to the nearest curly braces (let/const).
Explanation:
Function scope ignores inner block boundaries, while block scope confines variables strictly to their enclosing braces.
Correct Answer: a) It is created in the global lexical environment but does not become a property of the global window object.
Explanation:
Global let and const declarations avoid polluting the global window object properties.
Correct Answer: a) When an inner function retains references to large outer scope variables unnecessarily, preventing garbage collection
Explanation:
Lingering closures holding unneeded references can retain memory, preventing efficient garbage collection.
Correct Answer: a) Nested blocks are ignored by 'var', which punches through block boundaries to the enclosing function scope.
Explanation:
'var' does not respect block scoping, making inner block declarations accessible throughout the parent function.
Correct Answer: a) To inherit 'this' from the enclosing execution context, preventing common callback context loss bugs
Explanation:
Lexical binding saves developers from needing workarounds like `const self = this` inside callbacks.
Correct Answer: a) No, redeclaring a parameter name with 'let' in the same scope throws a SyntaxError.
Explanation:
Function parameters occupy the function body scope; redeclaring them with 'let' in that scope causes a duplicate identifier SyntaxError.
Correct Answer: a) Ensuring each module maintains private variable scopes, requiring explicit exports and imports to share state
Explanation:
Module architecture encapsulates file-level scope to promote clean, maintainable code structures.
Correct Answer: a) It throws a ReferenceError.
Explanation:
Unlike undeclared identifiers, checking 'typeof' on a block-scoped variable inside its TDZ throws a ReferenceError.
Correct Answer: a) A new lexical environment record is instantiated for the function call, capturing arguments and local declarations.
Explanation:
Each function call creates a fresh execution context with its own lexical environment record.
Correct Answer: a) Var declarations create window properties, whereas let/const declarations in global scope do not attach to window.
Explanation:
Let and const keep the global window object clean from accidental property pollution.
Correct Answer: a) It implicitly creates a new global variable property.
Explanation:
Without strict mode, assigning to an undeclared identifier implicitly creates a global property, which is a major source of bugs.
Correct Answer: a) No, arrow functions lack an 'arguments' object and reference the outer scope's arguments instead.
Explanation:
Arrow functions do not bind local arguments; rest parameters (`...args`) should be used instead.
Correct Answer: a) Unpredictable variable resolution depending on caller execution stacks rather than code authorship
Explanation:
Dynamic scoping makes it difficult to reason about code because variable values change based on who calls the function.
Correct Answer: a) It points to the outer lexical environment, forming the backbone of the scope chain for identifier resolution.
Explanation:
The outer environment reference enables the engine to traverse up the scope chain during variable lookups.
Correct Answer: a) Inner closures can read and update variables in all enclosing outer scopes they reference, maintaining shared state.
Explanation:
Closures maintain live references to their outer variables, allowing state to persist and update across calls.
Correct Answer: a) The property modification succeeds because const prevents variable reassignment, not property mutation.
Explanation:
const locks the binding reference, but the underlying object data remains fully mutable.
Correct Answer: a) Class bodies execute in strict mode by default and have their own lexical scope.
Explanation:
Classes enforce strict mode rules implicitly and maintain encapsulated scopes for their methods and static members.
Correct Answer: a) In non-strict mode, 'let' can sometimes be used as an identifier, but in strict mode or ES6 modules it is a reserved keyword.
Explanation:
To ensure future compatibility and prevent errors, 'let' is a reserved keyword in modern JavaScript.
Correct Answer: a) It can lead to unexpected 'undefined' values if variables are accessed before their assignment line.
Explanation:
Hoisting initializes 'var' as undefined, which often leads to subtle bugs if variables are used prematurely.
Correct Answer: a) Parameters are scoped to the arrow function body and inherit lexical 'this' from the outer scope.
Explanation:
Arrow function parameters act as local variables inside the function body scope.
Correct Answer: a) The undesirable practice of declaring too many variables in the global scope, increasing the risk of naming collisions
Explanation:
Scope pollution clutters the global namespace, making code fragile and prone to accidental overwrites.
Correct Answer: a) It throws a ReferenceError.
Explanation:
If an identifier cannot be found after traversing all the way to the top of the scope chain, a ReferenceError is thrown.
Correct Answer: a) Every execution context contains a lexical environment component that stores variable and scope information.
Explanation:
The lexical environment is a core internal component of an execution context responsible for managing variable bindings.
Correct Answer: a) Yes, inner blocks can declare variables with the same names as outer block variables, successfully shadowing them.
Explanation:
Block scoping fully supports nested scopes and variable shadowing for let and const declarations.
Correct Answer: a) Default parameters have their own intermediate scope separate from both the function body scope and the outer calling scope.
Explanation:
Default parameters evaluate in their own scope, meaning parameters defined earlier can be referenced by later default parameters.
Related Posts
New
New
New

JavaScript Hoisting MCQs
Hoisting is a fundamental mechanism in JavaScript where variable and function declarations are notionally moved to the top of their…
August 29, 2026By MCQs Generator

JavaScript Arrays & Array Methods MCQs
JavaScript arrays are dynamic, high-level list-like data structures designed to store ordered collections of data types under a single variable.…
August 29, 2026By MCQs Generator

JavaScript OOP MCQs for Developer Interviews & Certification
Object-Oriented Programming (OOP) in JavaScript allows developers to structure applications into modular, reusable objects that pair state (properties) with behavior…
August 29, 2026By MCQs Generator
Related Categories
New












AI & Data Science MCQ
5 topics
By MCQs Generator
New
Arts & Humanities MCQ
4 topics
By MCQs Generator
New
Civil Engineering MCQ
4 topics
By MCQs Generator
New
Commerce & Business MCQ
4 topics
By MCQs Generator
New
Competitive Exams MCQ
5 topics
By MCQs Generator
New
Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator
New
General Knowledge MCQ
2 topics
By MCQs Generator
New
General Science MCQ
4 topics
By MCQs Generator
New
Law & Judiciary MCQ
3 topics
By MCQs Generator
New
Mechanical Engineering MCQ
4 topics
By MCQs Generator
New
Medical & Health Sciences MCQ
4 topics
By MCQs Generator
New
Modern Tech Fields MCQ
3 topics
By MCQs Generator