DEV Community

Cover image for var vs let vs const in JavaScript

var vs let vs const in JavaScript

Tyler McGinnis on January 01, 2019

In this post you'll learn two new ways to create variables in JavaScript (ES6), let and const. Along the way we'll look at the differences between ...
Collapse
 
stefandjokic profile image
Stefan Đokić

The explanation is clear and concise, and the great examples make it easy to read and digest. Loved it, especially the summary at the end! 😄

Collapse
 
thekashey profile image
Anton Korzunov

It's 2019, it's not a good time to compare var and let/const.

What if to compare let, const and Readonly from TS/Flow?

const constVariable: Record<string, any> = {};

constVariable.b = "is it const?";

const reallyConstVariable: Readonly<Record<string, any>> = {};

reallyConstVariable.b = "is it const?";
Collapse
 
tylermcginnis profile image
Tyler McGinnis

I'll be sure to ask your permission next time I write something.

Collapse
 
jakedohm_34 profile image
Jake Dohm

Great work on this, Tyler, very thorough! Looking forward to more quality content ❤️

Collapse
 
wilfred05777 profile image
Wilfred Erdo

great article

Collapse
 
boceto1 profile image
Jean Karlo Obando Ramos

Hi Tyler. Great article.
I have a little doubt. How the interpreter of JS can know if a variable was declared with var or let before this happen? 🤔

Collapse
 
justinw7 profile image
JustinW7

can function scope can act as a block scope when no function is there ?

Collapse
 
safaelmali profile image
Safa Elmali

"In JavaScript, there are two kinds of scope - global scope, and function scope."

Why don't we say block scope as well 🙄