Skip to content

Standard Built-in Objects

JavaScript provides a rich set of built-in objects that form the foundation of the language. This section covers all standard built-in objects, their methods, and properties.

  • globalThis - Universal global object reference
  • Infinity - Numeric value representing infinity
  • NaN - “Not-a-Number” value
  • undefined - Primitive value undefined

The Object constructor creates object wrappers for the given value.

// Object creation
const obj = new Object();
const literal = { key: 'value' };
// Static methods
Object.keys(obj); // Get object keys
Object.values(obj); // Get object values
Object.entries(obj); // Get key-value pairs
Object.assign(target, source); // Copy properties
Object.freeze(obj); // Make object immutable
Object.seal(obj); // Prevent property addition/deletion

Key Methods:

Functions are first-class objects in JavaScript.

// Function declaration
function greet(name) {
return `Hello, ${name}!`;
}
// Function expression
const add = function(a, b) {
return a + b;
};
// Arrow function
const multiply = (a, b) => a * b;
// Function methods
greet.call(thisArg, 'World');
greet.apply(thisArg, ['World']);
const boundGreet = greet.bind(thisArg);

Boolean object represents a logical entity and can have two values: true and false.

// Boolean values
const isTrue = true;
const isFalse = false;
// Boolean constructor (avoid)
const boolObj = new Boolean(false); // Object, not primitive
// Conversion to boolean
Boolean(1); // true
Boolean(0); // false
Boolean('hello'); // true
Boolean(''); // false
!!value; // Convert to boolean (preferred)

Symbols are unique identifiers, useful for object property keys.

// Create symbols
const sym1 = Symbol();
const sym2 = Symbol('description');
const sym3 = Symbol.for('global'); // Global symbol registry
// Use as object keys
const obj = {
[sym1]: 'value1',
[sym2]: 'value2'
};
// Well-known symbols
Symbol.iterator; // Define iteration behavior
Symbol.toStringTag; // Customize Object.prototype.toString
Symbol.hasInstance; // Customize instanceof behavior

The Number object is a wrapper for primitive numeric values.

// Number literals
const integer = 42;
const float = 3.14159;
const scientific = 1.23e10;
const binary = 0b1010; // 10 in decimal
const octal = 0o755; // 493 in decimal
const hex = 0xFF; // 255 in decimal
// Number properties
Number.MAX_VALUE; // Largest representable number
Number.MIN_VALUE; // Smallest positive number
Number.MAX_SAFE_INTEGER; // Largest safe integer
Number.POSITIVE_INFINITY; // Positive infinity
Number.NaN; // Not-a-Number
// Number methods
Number.isNaN(value); // Check if value is NaN
Number.isFinite(value); // Check if value is finite
Number.parseInt(string); // Parse integer
Number.parseFloat(string); // Parse floating point

BigInt provides a way to represent integers larger than Number.MAX_SAFE_INTEGER.

// Create BigInt
const big1 = 123n;
const big2 = BigInt(123);
const big3 = BigInt('123456789012345678901234567890');
// Operations
const sum = big1 + big2;
const product = big1 * big2;
// Cannot mix BigInt with regular numbers
// const mixed = big1 + 123; // TypeError
const mixed = big1 + BigInt(123); // OK

Math is a built-in object providing mathematical constants and functions.

// Constants
Math.PI; // π (pi)
Math.E; // Euler's number
Math.LN2; // Natural logarithm of 2
// Basic operations
Math.abs(-5); // 5
Math.round(4.7); // 5
Math.ceil(4.1); // 5
Math.floor(4.9); // 4
Math.max(1, 2, 3); // 3
Math.min(1, 2, 3); // 1
// Advanced functions
Math.pow(2, 3); // 8 (2^3)
Math.sqrt(16); // 4
Math.random(); // Random number 0-1
Math.sin(Math.PI / 2); // 1

Date objects represent a single moment in time.

// Create dates
const now = new Date();
const specific = new Date('2024-01-01');
const fromValues = new Date(2024, 0, 1); // Year, month (0-based), day
// Get date components
now.getFullYear(); // Year (4 digits)
now.getMonth(); // Month (0-11)
now.getDate(); // Day of month (1-31)
now.getDay(); // Day of week (0-6)
now.getHours(); // Hours (0-23)
now.getMinutes(); // Minutes (0-59)
// Format dates
now.toISOString(); // ISO string
now.toLocaleDateString(); // Locale date
now.toLocaleTimeString(); // Locale time

Strings are sequences of characters used to represent text.

// String creation
const str1 = 'Hello';
const str2 = "World";
const template = `Hello, ${name}!`;
// String methods
str.length; // String length
str.charAt(0); // Character at index
str.indexOf('llo'); // First occurrence index
str.lastIndexOf('l'); // Last occurrence index
str.slice(1, 4); // Extract substring
str.substring(1, 4); // Extract substring (legacy)
str.substr(1, 3); // Extract substring (deprecated)
// String transformation
str.toLowerCase(); // Convert to lowercase
str.toUpperCase(); // Convert to uppercase
str.trim(); // Remove whitespace
str.trimStart(); // Remove leading whitespace
str.trimEnd(); // Remove trailing whitespace
str.replace('old', 'new'); // Replace first occurrence
str.replaceAll('old', 'new'); // Replace all occurrences
// String testing
str.startsWith('He'); // Check if starts with
str.endsWith('lo'); // Check if ends with
str.includes('ell'); // Check if contains
str.match(/pattern/); // Match regular expression

Regular expressions are patterns used to match character combinations in strings.

// Create RegExp
const regex1 = /pattern/flags;
const regex2 = new RegExp('pattern', 'flags');
// Common flags
const caseInsensitive = /hello/i; // Case insensitive
const global = /hello/g; // Global (find all)
const multiline = /^hello/m; // Multiline
const unicode = /\u{1F600}/u; // Unicode
// Methods
regex.test(string); // Test if pattern matches
regex.exec(string); // Execute and return match info
string.match(regex); // Find matches in string
string.replace(regex, replacement); // Replace matches
string.split(regex); // Split string by pattern

Arrays are list-like objects for storing multiple values.

// Array creation
const arr = [1, 2, 3];
const arr2 = new Array(5); // Array with 5 empty slots
const arr3 = Array.from('hello'); // ['h', 'e', 'l', 'l', 'o']
const arr4 = Array.of(1, 2, 3); // [1, 2, 3]
// Array methods - Mutating
arr.push(4); // Add to end
arr.pop(); // Remove from end
arr.unshift(0); // Add to beginning
arr.shift(); // Remove from beginning
arr.splice(1, 2, 'a'); // Remove/insert elements
arr.reverse(); // Reverse in place
arr.sort(); // Sort in place
// Array methods - Non-mutating
arr.concat([4, 5]); // Combine arrays
arr.join(', '); // Join to string
arr.slice(1, 3); // Extract portion
arr.indexOf(2); // Find index
arr.includes(2); // Check if contains
// Array iteration
arr.forEach(item => console.log(item));
arr.map(item => item * 2);
arr.filter(item => item > 1);
arr.reduce((sum, item) => sum + item, 0);
arr.find(item => item > 1);
arr.findIndex(item => item > 1);

TypedArrays provide a mechanism for accessing raw binary data.

// Different typed array types
const int8 = new Int8Array(8); // 8-bit signed
const uint8 = new Uint8Array(8); // 8-bit unsigned
const int16 = new Int16Array(8); // 16-bit signed
const uint16 = new Uint16Array(8); // 16-bit unsigned
const int32 = new Int32Array(8); // 32-bit signed
const uint32 = new Uint32Array(8); // 32-bit unsigned
const float32 = new Float32Array(8); // 32-bit float
const float64 = new Float64Array(8); // 64-bit float
// From existing data
const buffer = new ArrayBuffer(16);
const view = new Int32Array(buffer);

Map objects hold key-value pairs and remember the original insertion order.

// Create Map
const map = new Map();
const map2 = new Map([
['key1', 'value1'],
['key2', 'value2']
]);
// Map methods
map.set('key', 'value'); // Set key-value pair
map.get('key'); // Get value by key
map.has('key'); // Check if key exists
map.delete('key'); // Delete key-value pair
map.clear(); // Remove all entries
map.size; // Number of entries
// Map iteration
for (const [key, value] of map) {
console.log(key, value);
}
map.forEach((value, key) => console.log(key, value));
Array.from(map.keys()); // Get all keys
Array.from(map.values()); // Get all values
Array.from(map.entries()); // Get all entries

Set objects store unique values of any type.

// Create Set
const set = new Set();
const set2 = new Set([1, 2, 3, 3]); // [1, 2, 3]
// Set methods
set.add(1); // Add value
set.add(2).add(3); // Chainable
set.has(1); // Check if value exists
set.delete(1); // Delete value
set.clear(); // Remove all values
set.size; // Number of values
// Set iteration
for (const value of set) {
console.log(value);
}
set.forEach(value => console.log(value));
Array.from(set); // Convert to array

WeakMap objects are collections of key-value pairs where keys are objects and values can be arbitrary values.

const wm = new WeakMap();
const obj = {};
// Only object keys allowed
wm.set(obj, 'value');
wm.get(obj); // 'value'
wm.has(obj); // true
wm.delete(obj); // true
// Keys are weakly referenced (garbage collected when no other references)

WeakSet objects store unique object references.

const ws = new WeakSet();
const obj = {};
// Only objects can be stored
ws.add(obj);
ws.has(obj); // true
ws.delete(obj); // true
// Objects are weakly referenced

ArrayBuffer represents a generic, fixed-length raw binary data buffer.

// Create buffer
const buffer = new ArrayBuffer(16); // 16 bytes
// Cannot directly manipulate ArrayBuffer
// Must use DataView or TypedArray
const view = new DataView(buffer);
const int32View = new Int32Array(buffer);
// DataView methods
view.setInt8(0, 42); // Set 8-bit integer at offset 0
view.getInt8(0); // Get 8-bit integer at offset 0
view.setInt32(4, 0x12345678, true); // Little endian

JSON provides methods for parsing and stringifying JSON data.

// Stringify
const obj = { name: 'John', age: 30 };
const json = JSON.stringify(obj);
const prettyJson = JSON.stringify(obj, null, 2); // Formatted
// Parse
const parsed = JSON.parse(json);
// With replacer/reviver
const customJson = JSON.stringify(obj, (key, value) => {
return typeof value === 'string' ? value.toUpperCase() : value;
});
const customParsed = JSON.parse(json, (key, value) => {
return typeof value === 'string' ? value.toLowerCase() : value;
});

Promises represent the eventual completion or failure of an asynchronous operation.

// Create Promise
const promise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Success!');
// reject(new Error('Failed!'));
}, 1000);
});
// Promise methods
promise.then(result => console.log(result));
promise.catch(error => console.error(error));
promise.finally(() => console.log('Done'));
// Static methods
Promise.resolve(value); // Create resolved promise
Promise.reject(error); // Create rejected promise
Promise.all([p1, p2, p3]); // Wait for all
Promise.allSettled([p1, p2]); // Wait for all to settle
Promise.race([p1, p2]); // First to complete
Promise.any([p1, p2]); // First to resolve

Generator functions can be exited and later re-entered.

// Generator function
function* numberGenerator() {
yield 1;
yield 2;
yield 3;
return 'done';
}
// Use generator
const gen = numberGenerator();
console.log(gen.next()); // { value: 1, done: false }
console.log(gen.next()); // { value: 2, done: false }
console.log(gen.next()); // { value: 3, done: false }
console.log(gen.next()); // { value: 'done', done: true }
// Iterate generator
for (const value of numberGenerator()) {
console.log(value); // 1, 2, 3
}

Async functions return promises and can use await.

// Async function
async function fetchData() {
try {
const response = await fetch('/api/data');
const data = await response.json();
return data;
} catch (error) {
console.error('Error:', error);
throw error;
}
}
// Use async function
fetchData()
.then(data => console.log(data))
.catch(error => console.error(error));

Reflect provides methods for interceptable JavaScript operations.

const obj = { x: 1, y: 2 };
// Reflect methods mirror Proxy handler methods
Reflect.get(obj, 'x'); // 1
Reflect.set(obj, 'z', 3); // true
Reflect.has(obj, 'x'); // true
Reflect.deleteProperty(obj, 'x'); // true
Reflect.ownKeys(obj); // ['y', 'z']
Reflect.defineProperty(obj, 'a', {
value: 42,
writable: true
});

Proxy enables creating a proxy for another object to intercept operations.

const target = { x: 1, y: 2 };
const proxy = new Proxy(target, {
get(obj, prop) {
console.log(`Getting ${prop}`);
return obj[prop];
},
set(obj, prop, value) {
console.log(`Setting ${prop} to ${value}`);
obj[prop] = value;
return true;
},
has(obj, prop) {
console.log(`Checking if ${prop} exists`);
return prop in obj;
}
});
proxy.x; // Logs: "Getting x", returns 1
proxy.z = 3; // Logs: "Setting z to 3"
'y' in proxy; // Logs: "Checking if y exists", returns true

This reference covers all major built-in objects in JavaScript. Each object has its own dedicated page with detailed examples, browser compatibility, and best practices.