Yesterday I wrote about how if you want to write a goal in JavaScript that’s fixed, you should use const
to declare it. But if you want to keep it flexible, use var
or the let
.
But what if I have more than one goal? Then I want to push them into an array, like this:
// First, I'll create the array.
const goals = new Array();
// Then I'll add or push a goal into the array.
goals.push('Write more');
// I can even push multiple values at once.
goals.push('Take family on vacation','Ride bike more');
Now wait a minute. Didn’t I declare the array using const
? Doesn’t that mean that the array is constant and therefor unchangeable? That’s what I thought, but it turns out that declaring a variable as an array using const
means the variable must stay as an array, but the array’s contents can still change.