MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/gd8x2z/var_vs_let_vs_const/fphws3k/?context=3
r/learnjavascript • u/golovatuy • May 04 '20
81 comments sorted by
View all comments
81
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" 2 u/redsandsfort May 04 '20 it doesn'tfunction fn(){var x = 'cool';return x + 'dude';}console.log(windox.x) // undefined 2 u/cyphern May 04 '20 You're correct that the behavior i mentioned doesn't happen for local variables.
18
By "global scope" I think they mean "secretly copies your variable to the window object"
window
2 u/redsandsfort May 04 '20 it doesn'tfunction fn(){var x = 'cool';return x + 'dude';}console.log(windox.x) // undefined 2 u/cyphern May 04 '20 You're correct that the behavior i mentioned doesn't happen for local variables.
2
it doesn't
function fn(){var x = 'cool';return x + 'dude';
}
console.log(windox.x) // undefined
2 u/cyphern May 04 '20 You're correct that the behavior i mentioned doesn't happen for local variables.
You're correct that the behavior i mentioned doesn't happen for local variables.
81
u/senocular May 04 '20
const and let can be used in the global scope just as much as var can.