DEV Community

Discussion on: Concepts You Need to Know If You are a JavaScript Beginner

Collapse
 
shyclown profile image
Roman Moravcik • Edited

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.

Collapse
 
axlyaguana11 profile image
Axel Yaguana

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.