DEV Community

Discussion on: var, let & const in JavaScript

Collapse
 
lakshayne profile image
Lakshay Sharma

i just googled it and it says something like this and i am kind of confused now🤔🤔🤔

The main difference between let and var is that scope of a variable defined with let is limited to the block in which it is declared while variable declared with var has the global scope. So we can say that var is rather a keyword which defines a variable globally regardless of block scope.

Collapse
 
kunalt96 profile image
Kunal Tiwari

Yes, that what I wrote above. Yes, let has block scope and var has functional scope. You are mixing two things here and that is what confusing you. Whenever any variables declared outside function, outside blocks in globally - either be let or var, it will have full global scope

Collapse
 
lakshayne profile image
Lakshay Sharma

ok than you very much 👍👍

Thread Thread
 
kunalt96 profile image
Kunal Tiwari

Always welcome buddy :)