+ 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?

13th Aug 2022, 2:59 AM
Ray
Ray - avatar
3 odpowiedzi
+ 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.
13th Aug 2022, 3:07 AM
Chris Coder
Chris Coder - avatar
+ 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 ...
13th Aug 2022, 3:27 AM
Ipang
0
Chris Coder is this a potential walrus??!
13th Aug 2022, 12:40 PM
ρү૨œdԌ૨ ×
ρү૨œdԌ૨ × - avatar