66 likes
路
179 reads
6 comments
Nice blog one suggestion can you blog more like in table content view?
Well explained sir. 馃槃
can you please explain how this code is functioning? foo(); if (true) { function foo() { console.log(1); } } else { function foo() { console.log(2); } }
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
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();
Good blog keep it up !!鉁岋笍