Beginner JavaScript Practice Set: Function Execution Context
Last Updated: June 27, 2025
Understanding how functions work in JavaScript is fundamental to becoming a confident and capable developer. One of the most important — yet often misunderstood — concepts is the Function Execution Context. Every time a function is called, a new execution context is created, with its own scope, variables, and access to the parent environment. This article presents 20 beginner-friendly JavaScript practice questions designed to help you grasp how execution contexts are created, managed, and destroyed. From simple function calls to nested scopes and closures, each challenge is crafted to build your foundational knowledge step by step. Whether you’re just starting out or looking to strengthen your core understanding, these exercises will set you on the right path.
Basic Function Execution
Write a function
greet()that logs"Hello, World!"and call it.Create a function
sum(a, b)that returns the sum of two numbers. Call it with any values.Create a function
printName(name)that prints"My name is <name>". Call it inside another function.Create two functions:
outer()andinner(). Callinner()from insideouter()and see the order of execution.Declare a global variable, then access it inside a function. What is logged?
Scope and Variable Shadowing
Create a variable
x = 10outside a function and anotherx = 5inside a function. Log the value ofxinside and outside.Write a function that declares a variable using
letand try accessing it outside the function.Write two nested functions, both using a variable named
message. Log it from both levels. Does it shadow?
Call Stack Practice
Create three functions
a(),b(), andc()wherea()callsb()andb()callsc(). Log from each to understand the call stack.What happens if you call a function before it is defined using
functionkeyword vsconst(arrow function)?
Lexical Environment
Create a nested function that accesses a variable from its parent function.
Create a counter function using a local variable
countthat increases each time it’s called.
Errors and Hoisting
Call a function that uses a
vardeclared variable before it’s declared. What happens?Call a function that uses a
letorconstvariable before it’s declared. What error occurs?
Closures (Introductory)
Write a function that returns another function. The inner function should access a variable from the outer one.
Create a
makeMultiplier(factor)function that returns a function to multiply numbers by thefactor.
Multiple Calls and Reuse
Write a function
logTime()that logs the current time. Call it three times. Observe the output.Create a
greetUser(name)function. Call it with 3 different names.
Return vs Console Log
Write a function
calculate(a, b)that returns the result. Log it from the outside.Modify the above function to console.log instead of return. Can you use the result outside the function?
