Learn Introductory JavaScript by Building a Pyramid Generator - Step 7

This is the code:

let character = 'Hello';
console.log(character);
character = "World";
console.log(character);

And this is how the console looks:


My question is how is the console still able to access the “old” value 'Hello' even though the variable value has been reassigned?

its not going back in time,

  • its simply going sequentially,
  • its executing “one line of code at a time” and then move onto next line

if you look again its simply showing you what “value” of “character” was after executing line 1

and then after updating its value in line3, its showing its updated value in line4

hope that was helpful, ask away if you have questions, happy coding :slight_smile:

1 Like