Your Code Deserves a Lift
Test your JavaScript programming skills by solving the given puzzle about variable scoping and hoisting.
We'll cover the following...
We'll cover the following...
Puzzle code
Carefully read the code given below:
Press + to interact
let temp = 25;function displayTemperature() {console.log(`Current temperature: ${temp} °C`);}function forecastTemperature() {console.log(`Expected temperature: ${temp} °C`);var temp = 28;}displayTemperature();forecastTemperature();
Your task: Guess the output
Try to guess the output of the above code. Attempt the following quiz to assess your understanding.
Q
What is the output of the code above?
A)
Current temperature: 25 °C
Expected temperature: 25 °C
B)
Current temperature: 25 °C
Expected temperature: undefined °C
C)
Current temperature: 25 °C
Expected temperature: 28 °C
D)
Current temperature: 28 °C
Expected temperature: 28 °C
Let’s discuss this code and output together in the next lesson.