Variable declared with "var" does not have global scope, it is function scoped.
// global scope was declared when you did not use var, I think nowdays you get error
x = 5; // global scope
var x = 5 // function scope
let, const x = 5 // block scoped
One more... thing since you touched the arrow functions and "this" I think you should explain the difference between arrow functions and normal functions.
Yes, you're right. var has function scope, not global at all. When you declare var into curly braces you can access the variable outside the block code, and it could be misunderstood. But definitely, it's FUNCTION SCOPE.
I think I need another post to explain differences between arrow and normal funtions.
Thanks for your feedback. I really appreciate it.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Variable declared with "var" does not have global scope, it is function scoped.
// global scope was declared when you did not use var, I think nowdays you get error
x = 5; // global scope
var x = 5 // function scope
let, const x = 5 // block scoped
One more... thing since you touched the arrow functions and "this" I think you should explain the difference between arrow functions and normal functions.
Hi, Roman.
Yes, you're right. var has function scope, not global at all. When you declare var into curly braces you can access the variable outside the block code, and it could be misunderstood. But definitely, it's FUNCTION SCOPE.
I think I need another post to explain differences between arrow and normal funtions.
Thanks for your feedback. I really appreciate it.