Const vs. Let: What’s the Difference?

Jackson Reeves
2 min readFeb 22, 2021

When defining a new variable in JavaScript, you either use const or let (there’s also var out there in the ether, but it’s been superannuated). Const means the variable will remain constant, as in it can’t be changed; let means the variable can be changed to whatever you want after initially defining it. At first, this seemed pretty basic, but then I saw const used to define empty arrays and objects that could be added to later. But wait, isn’t that changing it? Does const not mean anything? Is nothing sacred?

I think I’ve figured it out.

It all has to do with the type of data versus the content of the data. Type of data means how you would categorize the data. For instance, “hello” is a string. In contrast, the content of the data means what that data actually contains — the essence of the data. In terms of the above string, its content is the idea of a greeting and the specific way it’s conveyed (it ain’t “hi,” it’s “hello). A variable defined with const can’t change its type, but depending on its type, it might be able to change its content.

When it comes to “basic” types — like numbers, strings, and Booleans — you can’t change its type after declaring it with const, and you can’t change its content either. If you define myNum as a _const _with the value 5, then you can’t later change it to have a value of 6.

However, with “container” types — like arrays and objects — while you still can’t change its type after declaring it with const, you can change its content. If you define myArray as a const and set it equal to an empty array, you can always add to it later. And delete from it. The only thing you can’t do is change its type. You can’t make myArray an object at some later point in time.

--

--

Jackson Reeves

Inquisitive full-stack developer with more than a decade of experience in education and journalism.