LearnFrenzy
Sign in Take a free test

Scope and Hoisting · Exercise 1 of 4

Scope and Hoisting Scope and Hoisting MCQ

  • 15 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on JavaScript scope and hoisting: kinds of scope, the scope chain, lexical scope, hoisting of functions, var, let, const and classes, execution contexts, closures, module scope and globalThis. Pick an option to check your answer instantly.

Question 1 Medium

JavaScript uses lexical scope. What does that mean?

A A function's accessible variables are decided by where it is written in the code, not where it is called
B Variables are looked up in the caller's scope first
C Scope is decided when the function is called
D Only global variables are accessible inside functions
Question page & discussion
Question 2 Easy

When a variable is used inside a nested function, in which order does the engine look for it?

A Global scope first, then inwards
B Only the current scope
C Every scope in the program at once
D Current scope first, then each enclosing scope outwards, ending with the global scope
Question page & discussion
Question 3 Easy

Which list contains only real kinds of scope in modern JavaScript?

A Global, class, object, loop
B Public, private, protected
C Static, dynamic, instance
D Global, module, function, block
Question page & discussion
Question 4 Easy

Which declaration is hoisted together with its value, so it can be fully used before its line?

A var calc = 1;
B let calc = 1;
C function calc() {}
D class Calc {}
Question page & discussion
Question 5 Medium

What happens when code runs new Car() on a line before class Car {}?

A It works, because classes are hoisted like functions
B TypeError: Car is not a constructor
C ReferenceError: Car cannot be accessed before initialization
D It returns undefined
Question page & discussion
Question 6 Hard

What happens in the creation phase of a function's execution context?

A Every line of the function runs once without side effects
B Only the return statement is evaluated
C The function's code is compiled to machine code and saved
D Parameters are bound, var variables are set to undefined, function declarations are created, and let/const are registered uninitialised
Question page & discussion
Question 7 Easy

What happens when code reads a variable that is not declared in any scope of the chain?

A It evaluates to undefined
B It evaluates to null
C A ReferenceError is thrown
D A new global variable is created
Question page & discussion
Question 8 Easy

Function inner is defined inside function outer. Which statement is true?

A inner can use outer's variables, but outer cannot use inner's
B outer can use inner's variables, but not the other way round
C Neither can use the other's variables
D Both can use each other's variables
Question page & discussion
Question 9 Hard

In an ES module, var version = "1.0"; is written at the top level. Is it a property of the global object?

A Yes, like in classic scripts
B Only in browsers
C Only if the module is imported
D No – each module has its own scope, so even top-level var stays private to the module
Question page & discussion
Question 10 Medium

Which statement best defines a closure?

A A function that has finished running
B A function without parameters
C A function together with the scope it was created in, which it can still access after the outer function returns
D A block of code inside curly braces
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links