Variables and types

const and let, numbers, strings, booleans, null / undefined, and converting between types.

Runs in Zerethon IDE · Node.js 22 Official JavaScript documentation ↗
main.js
const name = 'Ada';  // cannot be reassigned
let count = 3;       // can change
count += 1;

console.log(typeof name, typeof count, typeof true, typeof undefined, typeof null);
console.log(Number('42') + 1, parseInt('7px', 10), parseFloat('2.5') * 2);
console.log(String(7) + 7, 7 + 7, '7' * 2);
console.log(7 / 2, Math.floor(7 / 2), 7 % 2, 2 ** 10);
console.log(0.1 + 0.2, (0.1 + 0.2).toFixed(2));

Output

string number boolean undefined object
43 7 5
77 14 14
3.5 3 1 1024
0.30000000000000004 0.30
  • Prefer const; use let when the value changes. Avoid var (function-scoped, easy to misuse).
  • There is one number type (64-bit floating point); use BigInt (10n) for huge whole numbers.
  • Use === and !==: == converts types first ('1' == 1 is true).
  • typeof null is "object" — a long-standing quirk; test with value === null.