DEV Community

Stephanie Sison
Stephanie Sison

Posted on • Edited on

Assigning and Declaring Values and Variables

As a current student learning how to code via JavaScript with little to no experience in the coding world even the simplest things can be thought of to be complicated. I found so far that I sometimes like to make things harder than it seems to be. For example, using let vs. const.

Some background information before we continue. Let and Const was introduced in 2015 when the ECMAScript 6 came out with the updates. ECMAScript or ES was created by developers to be a centralized organization to allow changes or additions in languages like JavaScript. The idea behind this organization is to add updates in an organized manner. Allowing one group to control what is updated to be used with the new language keeps the languages organized and efficient.

Before the introduction of let and const, there was var. The keyword var is one that is used in older browsers as it was part of the ECMAScript1 update. Since the ES6 update, let and const are the preferred uses when declaring a variable. And to go further on those lines, my instructor have strongly advised me to declare variables primarily using the keyword const. By declaring variables using const, it prevents you from accidentally re-declaring it later on in your code. And when you are working on a big project, will save you many headaches.

I did the pre-work that was assigned to me before starting my current program. I felt like I had this down, but when it came down to doing my first assignment with it in the actual program, I found it more difficult than it really needed to be. After researching and reading up on let vs. const, I finally realized that a value assigned to let is something that can be modified and that a value assigned to const is something you cannot.

Someone had mentioned to me to think of let as "reading and writing." It is something that you can follow, but also make changes to as necessary. Now think of const as "reading." It is something that cannot be erased nor changed once a value has been assigned to it.

Somehow this analogy is now stuck in my brain every time I come to a point where I need to use let or const. I will silently question myself whether or not I need "read and write" this value or just "read" it.

Top comments (0)