← Back to Roadmap

Number & Boolean

Easy

In plain terms

Numbers in JavaScript are always 64-bit floats. Use parseInt/parseFloat for conversion. Boolean has two values: true and false. Many values are truthy or falsy in conditionals.

What you need to know

  • 64-bit float
  • parseInt, parseFloat
  • Truthy/falsy

Try it yourself

Copy the code below and run it in your browser console or a code editor:

// Numbers
const n = 42;
const float = 3.14;
const hex = 0xff;
const inf = Infinity;
const notNum = NaN;

parseInt('42px');   // 42
parseFloat('3.14'); // 3.14

// Boolean
const t = true;
const f = false;

// Falsy: false, 0, -0, '', null, undefined, NaN
if (0) { }      // false
if ('hello') { } // true

Learn more

Dive deeper with these trusted resources: