0
0
Javascriptprogramming~15 mins

Global execution context in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Global Execution Context in JavaScript
📖 Scenario: Imagine you are writing a simple JavaScript program that runs in a web browser. You want to understand how JavaScript starts running your code and what happens first in the background.
🎯 Goal: You will create a simple JavaScript program that shows how variables and functions are handled in the global execution context. You will see how JavaScript prepares your code before running it.
📋 What You'll Learn
Create a global variable with a specific value
Create a global function that returns a string
Use a variable to store a message
Call the global function and store its result
Print the stored message and function result
💡 Why This Matters
🌍 Real World
Understanding the global execution context helps you write better JavaScript code that runs correctly in browsers or Node.js environments.
💼 Career
Many programming jobs require knowledge of how JavaScript runs code, especially for debugging and writing clean, efficient scripts.
Progress0 / 4 steps
1
Create a global variable
Create a global variable called greeting and set it to the string "Hello, world!".
Javascript
Need a hint?

Use let to create a variable named greeting and assign the text "Hello, world!".

2
Create a global function
Create a global function called getMessage that returns the string "This is the global execution context.".
Javascript
Need a hint?

Define a function named getMessage that returns the exact string "This is the global execution context.".

3
Store messages in variables
Create a variable called message and set it to the value of the global variable greeting. Then create another variable called contextMessage and set it to the result of calling the function getMessage().
Javascript
Need a hint?

Assign message the value of greeting. Assign contextMessage the value returned by calling getMessage().

4
Print the messages
Use console.log to print the variables message and contextMessage on separate lines.
Javascript
Need a hint?

Use console.log(message) and console.log(contextMessage) to show the values in the console.