Missing values and template literals

ECMAScript 2026

Read how JavaScript represents missing or invalid values, then put results into a string.

On this page

When does undefined appear?

A declared variable with no assigned value reads as undefined. Reading an absent property also gives undefined. Log each value separately to see where it came from.

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.

let receipt;
const order = { product: "Pen" };
console.log(receipt);
console.log(order.note);

What to expect Both lines print undefined.

Set an empty value with null

Set a value to null when your code deliberately records an absence. Here the note field exists and the shop has recorded that it has no note.

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 order = { product: "Pen", note: null };
console.log(order.note);
console.log(order.note === null);

What to expect The console prints null, then true.

Detect an invalid number with Number.isNaN()

NaN is a special number value that can result from an invalid calculation or conversion. NaN is unequal to itself, so use Number.isNaN(value) to detect it.

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 quantity = Number("two");
console.log(quantity);
console.log(Number.isNaN(quantity));

What to expect The console prints NaN, then true. Change "two" to "2" and compare.

Insert values with template literals

Backticks delimit a template literal. JavaScript evaluates the expression inside a dollar sign followed by braces and converts the result to string text. A template literal can also span multiple lines.

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 product = "Pen";
const quantity = 2;
const price = 1500;
console.log(`${product}: ${quantity * price} MMK`);

What to expect The console prints Pen: 3000 MMK. Change the quantity and run again.

Official references