Difference between Var, Let & Const

VAR

Scope

  • Functional Scope
  • Global Scope
  • Block Scope

Functional Scope

Global Scope

Block Scope

Functional Scope
Block Scope

Scope of VAR

Hoisting in Var

console.log (greeter);var greeter = “say hello”
var greeter;console.log(greeter); // greeter is undefinedgreeter = “say hello”

Problems with var

Problem of var

let

Scope of let

let is Block Scoped

Hoisting in let

Advantages of let over var

let can’t be re-declared

Const

Scope of Const

Hoisting of Const

Advantages of Const

  • A constant value cannot be re-assigned
  • A constant array can not be re-assigned
  • A constant object cannot be re-assigned
  • Change the elements of a constant array
  • Change the properties of a constant object

Conclusion

Difference between the three

--

--

--

I am a front-end developer from India with over one year of experience in freelancing with skills like Git, HTML5, CSS3, Bootstrap 4&5, and React.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The making of : Photo of the day by NASA web app

React Hooks | useState hook

React closer

Theming and Theme switching in React

Another wallet for your next Dapp

LET’S PEEK INTO BASICS OF REACT…

JavaScript For Beginner (JS Tutorial)

What is the difference in Java and Javascript?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ateev Duggal

Ateev Duggal

I am a front-end developer from India with over one year of experience in freelancing with skills like Git, HTML5, CSS3, Bootstrap 4&5, and React.

More from Medium

Basics of JavaScript and Version Controlling

Create a Nested Comment/Reply Box Using JavaScript Web Components

Coding Conditionals

Lesser-known JavaScript features — Part 2