Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion quiz/hoisting-iii_en.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@

There is no solution yet.
TLDR : -
2
1
undefined

Explaination

=> As we know variable declaration,hence the code in global scope will be hoisted i.e
1. a is decalared in window object and assigned undefined.
2. function func is saved in the memory.
3. b is decalared in window object and assigned undefined

=> now during the code execution
1. var a = 1, will assign 1 to a;
2. when our code encounters func() it creates is own execution context in which hoisting happend again
2.1 now var a is decalared and assigned undefined initially
2.2 encountering a = 2 will change a's value to 2.
2.3 console.log(a) will print 2.

3. now func's execution context is closed
4. code encounters console.log(a) and print global a which is 1
5. if (!('b' in window)) this condition is checked and it comes out as false as b is already hoisted with initial value of undefined
6.console.log(b) prints undefined


Would you like to [contribute to the solution](https://github.com/BFEdev/BFE.dev-solutions/blob/main/quiz/hoisting-iii_en.md)? [Contribute guideline](https://github.com/BFEdev/BFE.dev-solutions#how-to-contribute)