JavaScript data types and data structures - JavaScript | MDN

developer.mozilla.org

Tin mới

Dynamic and weak typing

JavaScript is a dynamic language with dynamic types. Variables in JavaScript are not directly associated with any particular value type, and any variable can be assigned (and re-assigned) values of all types:

typeof null === "object"

The Undefined type is inhabited by exactly one value: undefined.

double-precision 64-bit binary format IEEE 754 value

Number.MAX_SAFE_INTEGER

The BigInt type is a numeric primitive in JavaScript that can represent integers with arbitrary magnitude. With BigInts, you can safely store and operate on large integers even beyond the safe integer limit (Number.MAX_S

Beware of "stringly-typing" your code!

Enumerability and ownership of properties

Keyed collections: Maps, Sets, WeakMaps, WeakSets

These data structures take object references as keys. Set and WeakSet represent a collection of unique values, while Map and WeakMap represent a collection of key-value associations.

Symbol.prototype[Symbol.toPrimitive]()

The primitive coercion process is used where a primitive value is expected, but there's no strong preference for what the actual type should be. This is usually when a string, a number, or a BigInt are equally acceptable

Array.prototype.slice()

There are two numeric types: Number and BigInt. Sometimes the language specifically expects a number or a BigInt (such as Array.prototype.slice(), where the index must be a number); other times, it may tolerate either an

Primitive coercion

All data types, except Null, Undefined, and Symbol, have their respective coercion process. See string coercion, boolean coercion, and object coercion for more details.