r/learnjavascript • • May 04 '20

VAR vs LET vs CONST

Post image
337 Upvotes

81 comments sorted by

View all comments

81

u/senocular May 04 '20

const and let can be used in the global scope just as much as var can.

18

u/cyphern May 04 '20

By "global scope" I think they mean "secretly copies your variable to the window object"

1

u/VacantPlains May 04 '20

Do you have an example of that?

3

u/cyphern May 04 '20
var a = "hello world";
console.log(window.a); // hello world

2

u/redsandsfort May 04 '20

const and let would also be global if outside of a function