Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Hoisting: Call Before Declaration

Behind the Sceneseasy

Course · Section 8: How JavaScript Works Behind the Scenes · Lecture 98: Variable Environment: Hoisting and The TDZ

Implement `useHoisted(n)` that calls a function declaration `sq` defined later in the body, returning `n` squared. Function declarations are hoisted.

Sample tests

Input: useHoisted(4)
Output: 16
Input: useHoisted(0)
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • A function expression assigned to a const is not hoisted and would throw.
Visualize this concept: Hoisting →
Approach & explanation (try first)

Function declarations are hoisted, so sq can be called before its definition appears.

Loading...
⌘/Ctrl + Enter

Run your code to see results.