LESSON 09 OF 50

Convert explicitly to a number

Convert a numeric string with Number.

Official sourceECMAScript — Number constructor as a functionReviewed: 2026-08-26
STEP 1 · LEARN

How it works

When called as a function, Number converts its argument into a numeric value. Explicit conversion makes the intent clearer than accidental coercion.

Correct example
const raw = '42';
const amount = Number(raw);
console.log(amount);

raw remains a string, while amount receives the number 42 produced by conversion.

Common mistake
const raw = '42';
const amount = raw;

Copying the value does not change its type; amount remains a string.

STEP 2 · APPLY

Your exercise

Convert raw with Number, store the result in amount and print amount.

STEP 3 · RUN

Write and run the code

script.jsJAVASCRIPT
Isolated consoleisolated
Preparing the runtime…
Run the code to see the result.
The draft stays only in this browser.Isolated QuickJS · no DOM, session or network
STEP 4 · CHECK

What needs to pass

0%not checked
  • amount is declared with const.
  • amount uses Number(raw) conversion.
  • The output is 42.
Explain the solution logic

Number(raw) performs the explicit conversion, and the output confirms the resulting numeric value.