DEV Community

Discussion on: Notes on ECMAScript 6 (ES6)

Collapse
 
hardy613 profile image
Scott Hardy • Edited

Hey Patrick!

Thanks for the great question. I will try to answer by breaking it down first with var vs let and const

var is function scoped. let and const are block scoped. This is the biggest difference, to use the wise words of a work colleague: "let is what var should have been from the start."

That said the main difference with let vs const is that const does not allow re-declaring. This does tell a developer that it will not change as you mentioned, but more importantly, it is telling your program that it cannot change.

Some linters out there (AirBnB) will throw an error if you declare a let and never change or re-declare it, the error will be to use a const.

I hope I answered your question sufficiently.

Cheers!