Sign in
Log inSign up
haresh lakhwani

69 likes

163 reads

6 comments

jayesh patidar
jayesh patidar
Feb 25, 2023

Nice blog one suggestion can you blog more like in table content view?

Rishab Dodra
Rishab Dodra
Mar 11, 2023

Well explained sir. 馃槃

Nikita Gupta
Nikita Gupta
Mar 16, 2023

can you please explain how this code is functioning? foo(); if (true) { function foo() { console.log(1); } } else { function foo() { console.log(2); } }

2 replies
haresh lakhwani
haresh lakhwani
Author
Mar 17, 2023

Nikita Gupta i think it should give reference error and because we have foo() function invoked in global space but the deceleration of foo() in inside if or else block means it can be only invoked inside if or else function. Let me know if i missed something

Nikita Gupta
Nikita Gupta
Mar 17, 2023

haresh lakhwani thank you for your response sir but, why it's giving a reference error that foo () is not a function. If we do console.log (foo) at the top of the scope it indeed gives us a function in response which is the same inside if block, then why the error mentioning something else? I am not able to figure out that where I am mistaken?

Also, If we agree at this point that it can be only invoked inside if or else function, then how the same code is functioning, if we do this:

if (true) { function foo() { console.log(1); } } else { function foo() { console.log(2); } } foo();

Kospi
Kospi
Mar 22, 2023

Good blog keep it up !!鉁岋笍