0
0
Javascriptprogramming~15 mins

What execution context is in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
What execution context is
📖 Scenario: Imagine you are baking cookies in a kitchen. The kitchen is your workspace where you have all your ingredients and tools ready. In programming, the execution context is like that kitchen where your code runs and has access to everything it needs.
🎯 Goal: You will create a simple JavaScript program that shows how the execution context works by running code inside a function and logging messages to understand where the code is running.
📋 What You'll Learn
Create a variable in the global context
Create a function to represent a new execution context
Use console.log to show messages from global and function contexts
Call the function to see the execution context in action
💡 Why This Matters
🌍 Real World
Understanding execution context helps you know where your variables live and how your code runs step-by-step, which is important for debugging and writing clear code.
💼 Career
Many programming jobs require you to understand how code runs in different contexts to avoid bugs and write efficient, maintainable code.
Progress0 / 4 steps
1
Create a global variable
Create a variable called message in the global context and set it to the string 'Hello from global context'.
Javascript
Need a hint?

Use var to create a variable named message and assign the exact string.

2
Create a function to represent a new execution context
Create a function called showContext that creates a variable called message inside it with the value 'Hello from function context'.
Javascript
Need a hint?

Define a function named showContext and inside it, create a variable message with the exact string.

3
Log messages from both contexts
Inside the showContext function, add two console.log statements: one to print the local message variable, and one to print the global message variable using window.message.
Javascript
Need a hint?

Use console.log(message) to print the local message and console.log(window.message) to print the global message.

4
Call the function and see the output
Call the function showContext() to run the code and see the messages from both execution contexts printed in the console.
Javascript
Need a hint?

Simply call showContext() to run the function and see the output.