LearnFrenzy
Sign in Take a free test

Scope and Hoisting · Exercise 1 of 4

Scope and Hoisting Scope and Hoisting MCQ

  • 15 questions
  • Page 2 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 11 Hard

Which statement correctly contrasts scope and this?

A Both are decided by how the function is called
B Both are fixed when the code is written
C Scope is fixed by where code is written; this (in a normal function) is decided by how the function is called
D this is the same as the global scope
Question page & discussion
Question 12 Medium

What is globalThis?

A A standard way to reach the global object in any environment (window, self or global)
B The top-level this of a function
C A list of all global variables declared with let
D A Node.js-only module
Question page & discussion
Question 13 Medium

Inside a function, let total shadows an outer let total. How can the function read the outer one?

A It cannot by that name – rename one of the variables or pass the outer value in
B With outer.total
C With this.total
D With super.total
Question page & discussion
Question 14 Medium

What is the value of save on the first line of a scope that later contains var save = function () {};?

A The function
B null
C undefined
D It throws a ReferenceError
Question page & discussion
Question 15 Easy

Which is the best way to keep helper variables out of the global scope in modern code?

A Declare everything with var
B Put the code in an ES module (or at least inside a function or block)
C Prefix all names with g_
D Store them as properties of window
Question page & discussion
Up next · Exercise 2Predict the Output20 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links