Values, types, variables, and operators

ECMAScript 2026

A value is a piece of data a program works with. Learn to identify its kind, keep it under a name, and use it in a calculation or comparison.

On this page

Recognize strings, numbers, and booleans

The type describes what kind of value you have. Text in quotes is a string. An unquoted value such as 2500 is a number. true and false are boolean values. typeof reports a type name as a string.

How to try it Open a browser tab, then open Developer Tools → Console. Type the example or paste it into the Console after reviewing it, then run it. Reload before repeating declarations with the same names.

console.log(typeof "Pen");
console.log(typeof 2500);
console.log(typeof true);

What to expect The Console prints string, number, and boolean on separate lines.

Name a value with const or let

A variable is a name you use to refer to a value. A declaration introduces the name. The equal sign assigns a value. Use const when the name should keep pointing to the value assigned at creation, and let when the assignment may change.

How to try it Open a browser tab, then open Developer Tools → Console. Type the example or paste it into the Console after reviewing it, then run it. Reload before repeating declarations with the same names.

const price = 2500;
let quantity = 1;
cups = 2;
console.log(price, quantity);

What to expect The Console prints 2500 and 2. Changing quantity does not affect price.

If the result differs If you get an error about a name already being declared, reload the browser tab before running the example again.

Calculate and compare with operators

An operator acts on values. * multiplies, + adds two numbers, and >= checks whether the left side is at least the right side. === checks strict equality; the number 3 and the string "3" have different types. Use && when both checks have to be true.

How to try it Open a browser tab, then open Developer Tools → Console. Type the example or paste it into the Console after reviewing it, then run it. Reload before repeating declarations with the same names.

console.log(2500 * 2);
console.log(3 === "3");
console.log(3 >= 1 && 3 <= 6);

What to expect The results are 5000, false, and true, in that order.

Convert text before calculating

A value typed into an HTML input is commonly read as a string. Number() converts numeric text. NaN is a special number value that can signal failed conversion. Check it with Number.isNaN(). Treat blank input separately because Number("") gives 0.

How to try it Open a browser tab, then open Developer Tools → Console. Type the example or paste it into the Console after reviewing it, then run it. Reload before repeating declarations with the same names.

const count = Number("3");
console.log(count + 1);
console.log(Number.isNaN(Number("three")));

What to expect The Console prints 4, then true. Try "3" + 1 to see string concatenation produce "31".

Official references