DEV Community

Discussion on: Scopes Hoisting Closures | Tricky Interview questions

Collapse
 
dheerajk30 profile image
Dheeraj Khathuria • Edited

I think for your last question, the answer would be 35 10 and reference error because variable_2 and variable_3 are not in the scope of that part. I checked in the console for this, the output is 35 10 15 and reference error for variable_3. I dont understand how and why it is able to access variable_2, will it not be hoisted in the IIFE and function scoped to that level?
UPDATE: I missed that the variable_2 is undeclared and will be part of global scope

Collapse
 
raghav_0698 profile image
Raghav • Edited

the ouput will be like this-
35
10
15
reference error: variable_3 is not defined