Updating Variable Value
It's important to understand that the program executes sequentially. This means that one command is executed, and after it completes, the next command is executed. Let's explain this with an example:
let artist = "Edgar Allan Poe";
console.log("The best artist is " + artist);
artist = "William Shakespeare";
console.log("The best artist is " + artist);
This will print:
The best artist is Edgar Allan Poe
The best artist is William Shakespeare
First, we assigned the value "Edgar Allan Poe"
to the variable artist
. Then it printed The best artist is Edgar Allan Poe
because at that moment, the value of the artist
variable is "Edgar Allan Poe"
. Next, we changed the value of the artist
variable to "William Shakespeare"
. Now it printed The best artist is William Shakespeare
because the value of the artist
variable has been changed.
Notice that when we change the value of a variable, we no longer use the keyword (let
). We only use the keyword when we create the variable.
Instructions
On line 4, change the value of the firstName
variable to "Mike"
.
On line 5, insert the command from line 3:
console.log(firstName + " " + surname);
Start programming for free
7/10