Are you ready for another code challenge? Join me in this video as you test your coding knowledge with the simple quiz questions.
Don't forget to make your guess in the comments below.
-------------------------------------------------------------------------------------------
🔔Like and subscribe for more videos. 🔔
Connect me on linkedin :
https://www.linkedin.com/in/meenakshilodhi...
https://www.linkedin.com/in/rk-barnwal23/
------------------------------------------------------------------------------------------
Answer OPTION: C) ReferenceError
Explanation:
The code defines a variable x with a value of 10 in the outer scope.
Inside the foo() function, the let keyword is used to declare a new variable x with a value of 20. This creates a new block-scoped variable that shadows the outer variable x within the function.
When console.log(x) is executed inside the function, it tries to access the value of the inner variable x before it is declared. This results in a ReferenceError, as variables declared with let are not hoisted to the top of their block.
Hence, the output will be a ReferenceError.