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

  1. Write a function greet() that logs "Hello, World!" and call it.

  2. Create a function sum(a, b) that returns the sum of two numbers. Call it with any values.

  3. Create a function printName(name) that prints "My name is <name>". Call it inside another function.

  4. Create two functions: outer() and inner(). Call inner() from inside outer() and see the order of execution.

  5. Declare a global variable, then access it inside a function. What is logged?

Scope and Variable Shadowing

  1. Create a variable x = 10 outside a function and another x = 5 inside a function. Log the value of x inside and outside.

  2. Write a function that declares a variable using let and try accessing it outside the function.

  3. Write two nested functions, both using a variable named message. Log it from both levels. Does it shadow?

Call Stack Practice

  1. Create three functions a(), b(), and c() where a() calls b() and b() calls c(). Log from each to understand the call stack.

  2. What happens if you call a function before it is defined using function keyword vs const (arrow function)?

Lexical Environment

  1. Create a nested function that accesses a variable from its parent function.

  2. Create a counter function using a local variable count that increases each time it’s called.

Errors and Hoisting

  1. Call a function that uses a var declared variable before it’s declared. What happens?

  2. Call a function that uses a let or const variable before it’s declared. What error occurs?

Closures (Introductory)

  1. Write a function that returns another function. The inner function should access a variable from the outer one.

  2. Create a makeMultiplier(factor) function that returns a function to multiply numbers by the factor.

Multiple Calls and Reuse

  1. Write a function logTime() that logs the current time. Call it three times. Observe the output.

  2. Create a greetUser(name) function. Call it with 3 different names.

Return vs Console Log

  1. Write a function calculate(a, b) that returns the result. Log it from the outside.

  2. Modify the above function to console.log instead of return. Can you use the result outside the function?