JavaScript Variables and Types

JavaScript · 3 minute lesson

JavaScript lets a page work with information and respond to users. A variable gives a value a meaningful name. Use const when the binding will stay the same, and let when you need to assign a different value later. Clear names make even a small script easier to understand.

Common values include strings for text, numbers for calculations, and booleans for true-or-false choices. JavaScript also has null and undefined, which can represent missing information in different ways. Check the value you actually have before performing an operation that assumes a particular type.

A const declaration prevents reassignment of the variable; it does not make an object deeply immutable. You can still change properties on an object held by a const binding. Keep that distinction in mind when storing settings, lesson records, or other structured data.

Try the example

const topic = "JavaScript";
let completedLessons = 2;
completedLessons += 1;

const isReady = completedLessons >= 3;
console.log(topic, completedLessons, isReady);

Practice

Create variables for a course title, lesson count, and completion flag. Print them in the console. Change the lesson count, then explain which declaration needs let and which declarations can use const.

Continue learning: Official documentation.