+ 1
What happen if I declare a variable without a keyword? [Js]
Suppose I write like this: name = "Tom" Is the variable 'name' is var by default? This can print in console without an error. So what's happening in behind the scene?
3 Respostas
+ 3
Variables can be declared and initialize without the var keyword. However, a value must be assigned to a variable declared without the var keyword. The variables declared without the var keyword are global variables.
+ 3
There's a risk for accidental reassignment of variables defined without `var`, `let` or `const` specifier.
// global space
myName = "real slim shady";
function blah()
{
myName = "fake slim shady";
}
A call to blah() will reassign variable <myName> accidentally.
You should be careful of that ...
0
Chris Coder is this a potential walrus??!