Let, Const and Var

Talk it through out loud with your AI coach.

The problem

  • easy

A teammate asks why the style guide says to use const by default, let when a value changes, and never var. Explain the differences between the three, and what goes wrong in a for loop that uses var to create click handlers that each log their own loop number.

What a strong answer covers

  • How the three keywords differ in where a variable can be seen.
  • What const really protects, and what it leaves changeable.
  • What happens when a variable is used before the line that declares it.
  • Why a loop's handlers can all end up reporting the same number, and how the keyword choice changes that.

Common mistake: Assuming const makes a value fully unchangeable, when it only fixes which value the name points to.

Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.

Practise it out loud