let foo = 42; // foo is now a number
foo = "bar"; // foo is now a string
foo = true; // foo is now a booleanJavaScript data types and data structures / notebook
JavaScript data types and data structures
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const foo = 42; // foo is a number
const result = foo + "1"; // JavaScript coerces foo to a string, so it can be concatenated with the other operand
console.log(result); // 421console.log(42 / +0); // Infinity
console.log(42 / -0); // -Infinity// BigInt
const x = BigInt(Number.MAX_SAFE_INTEGER); // 9007199254740991n
x + 1n === x + 2n; // false because 9007199254740992n and 9007199254740993n are unequal
// Number
Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2; // true because both are 9007199254740992console.log({} + []); // "[object Object]"