Understand the idea

A variable binding lets you refer to a value by name. Use const when the binding will not be reassigned, and let when reassignment is part of the logic.

JavaScript values have types such as string, number and Boolean. A const binding cannot be assigned a different value later, but an object stored in it can still be modified. Prefer descriptive names over unexplained single letters.

Read the example

This is a JavaScript fragment. Run it in a browser console or an external script. Supply any HTML or data file named in the example first.

JavaScript · EXAMPLE
const projectName = "My gallery";
let photographCount = 12;
photographCount += 1;
console.log(projectName, photographCount);

A small mistake, explained

What goes wrong

The + operator can join strings. "12" + 1 produces "121", not 13.

How to fix it. Inspect the type with typeof. Convert a string with Number when a number is required, and handle invalid conversions.

Try it yourself

Run the code in the browser console. Replace 12 with "12" and explain the changed result before fixing it.

Further reading

ECMAScript — let and const

Original explanation and example prepared for HTML code FYI with AI assistance. Test the code in your own context. How these guides are made.