If you miss putting a var
/let
/const
keyword before a variable declaration, it becomes global and gets bind to the global object.
Usecase:
function getName() {
myVariable = 'shub'
return myVariable;
}
getName()
console.log(myVariable) // shub
myVariable
will become global and will be accessible everywhere in the program
Top comments (1)
"use strict"
? Or in TypeScript, I think you can putstrict: true
intsconfig.json
w3schools.com/js/js_strict.asp