DEV Community

Cover image for Day 8 – Var vs Let vs Const -Learning Node JS In 30 Days [Mini series]
Muhammad Ali (Nerdjfpb)
Muhammad Ali (Nerdjfpb)

Posted on • Originally published at blog.nerdjfpb.com

Day 8 – Var vs Let vs Const -Learning Node JS In 30 Days [Mini series]

Today we’re going to learn about var vs let vs const

Before ES6 VAR was the King. We used var in everywhere we wants to declare a variable

Alt Text

var variables can be re-declared and updated

Alt Text

Now we divide var with two different types one CONST & other LET

CONST is declared for those value which will not changed anytime! Or will not be updated at any point. const cannot be updated or re-declared, this will lead you to an error you if try

Alt Text

We use LET when their is a change of updating the variable

Alt Text

LET can be updated but not re-declared. This will give a error you can’t run code

Alt Text

So in es6 we use LET & CONST not Var!

Do you knew this before ?

You can see the graphical version here

Originally it published on nerdjfpbblog. You can connect with me in twitter or linkedin !

You can read the old posts from here --

Top comments (2)

Collapse
 
adam_cyclones profile image
Adam Crockett

I constantly use const, but don't let me get started on this subject, I varely use var. 🥁

Collapse
 
nerdjfpb profile image
Muhammad Ali (Nerdjfpb)

That's good! Var was mainly used before const and let.