freecoding.school100% FREE · NO SIGNUP
Script SpringsISSUE #9 of 29

number methods · toFixed · parseInt · isFinite

SparkyVSNaN the Trickster
Sparky saysNumber methods and helpers: toFixed, parseInt/parseFloat, Number(), isNaN, isFinite.

toFixed(2) formats to a fixed decimal string. parseInt/parseFloat pull a number from the front of a string; Number(x) converts strictly (whole string must be numeric). Number.isNaN and Number.isFinite are the reliable checks (prefer them over the global versions).

Power-ups you unlock

NaN the Trickster attacks — common mistakes

Boss battleparseInt "42px", convert "3.14" with Number, and format a price with toFixed(2).

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const o=[parseInt('42px',10), Number('3.14'), (19.5).toFixed(2)];
document.getElementById('o').textContent=o.join('\n');</script></body></html>
▶ Open the interactive comic issue
‹ Numbers · Int · Float · NaN · InfinityBigint · Arbitrary Precision ›