Function body have variable and print stmt , when outside of function first print then call body function give only error. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Function body have variable and print stmt , when outside of function first print then call body function give only error.

Please note, if you think, that was simple question, it may be, but many people just don 't know, so they' ll also be helped. function funScope(){ var appName ="HTMLINHINDI"; console.log(appName); } console.log(appName); funScope (); In this process, why the appname in the function body is not getting printed. I want to ask why the variable inside the body is not printing in the body itself. While it is accessible. First of all, understand what I am asking. https://code.sololearn.com/WJaJGrk6yADF/?ref=app Whereas outside of the function body, first call the function and then print, the variable located in the function body gets printed in the body. Whereas in contrast to print and call only the error comes. I am not talking about scope, focus in the console. https://code.sololearn.com/WXrdSCbHvk6g/?ref=app compare both link

30th Aug 2020, 9:49 AM
ASP
ASP - avatar
1 Answer
+ 2
If you have to use single variable inside function and outside function (basically everywhere) then use global variables only.
30th Aug 2020, 11:29 AM
Raj Chhatrala
Raj Chhatrala - avatar