vendredi 28 mai 2021

Global variables in javascript not working properly

So I was practicing javascript and I wrote the following code

function fun1(){
    globalVar = 5;
}
function fun2(){
console.log(globalVar);
}
fun2();

I am using vs code and I run the above code using node and it says that globalVar is undefined, I don't understand global variables well so a brief explanation would be appreciated.




Aucun commentaire:

Enregistrer un commentaire