Primitives in JavaScript

Posted by yhuang
Public (Editable by Users)
JavaScript
None
Edit
// The latest ECMAScript standard defines seven primitive data types:

// Boolean. true and false.
let b = true;
console.log(b);

// null. A special keyword denoting a null value. (Because JavaScript is case-sensitive, null is not the same as Null, NULL, or any other variant.)
let n = null;
console.log(null);

// undefined. A top-level property whose value is not defined.
let u1 = undefined;
let u2;
console.log(u1);
console.log(u2);

// Number. An integer or floating point number. For example: 42 or 3.14159.
let n1 = 42;
let n2 = 3.14159;
console.log(n1);
console.log(n2);

// BigInt. An integer with arbitrary precision. For example: 9007199254740992n.
let big = BigInt(9007199254740991);
console.log(big);

// String. A sequence of characters that represent a text value. For example: "Howdy"
let s = "Howdy";
console.log(s);

// Symbol (new in ECMAScript 2015). A data type whose instances are unique and immutable.
let sym1 = Symbol();
let sym2 = Symbol(42);
let sym3 = Symbol('foo');
console.log(sym1, sym2, sym3);