Member-only story

JavaScript Basics: Bindings

Attaching values to variables

Max N
3 min readJun 23, 2022
Photo by Jason Leung on Unsplash

When running a program in JavaScript, it remembers what values go where and when to update them. It updates values by replacing old values with new ones, but how does it do that? JavaScript will have to attach the value to something or the value is meaningless.

That is when binding or variables come in.

let num = 4 + 3;

The special keyword let tells JavaScript that you are going to define a variable. It is followed by the name of the variable num and an = operator to tell JavaScript what you want to attach to num. In this case, we want to add 4 and 3. The total is now tied to the num variable.

Instead of writing 4 + 3 multiple times in your program, you can mention only num. If you want to change the + operator to a * and multiply it, you can go to the original mention of the variable and change it. This is better than writing 4 + 3 multiple times in your code.

You can update num by adding another variable to it:

let inches = 20;
console.log(num + inches);

Since num + inches isn’t tied to a variable, the value is gone once the program is done. If it was attached to a variable, you could reuse that variable elsewhere in the code. As long as you mention the variable before…

--

--

Max N
Max N

Written by Max N

A writer that writes about JavaScript and Python to beginners. If you find my articles helpful, feel free to follow.

No responses yet