From e992f3249ee2e8d77df475ad1865532acb4b5ed5 Mon Sep 17 00:00:00 2001 From: Lakshay Shukla <52699472+shuklaksh@users.noreply.github.com> Date: Sun, 21 Jul 2024 03:24:57 +0530 Subject: [PATCH] Update hoisting-iii_en.md --- quiz/hoisting-iii_en.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/quiz/hoisting-iii_en.md b/quiz/hoisting-iii_en.md index 940b6aa0..d4722c64 100644 --- a/quiz/hoisting-iii_en.md +++ b/quiz/hoisting-iii_en.md @@ -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)