JavaScript Reference
Complete guide to JavaScript methods and properties
📚 Array (25)
map()
Creates a new array with the results of calling a provided function on every element in the calling array.
filter()
Creates a new array with all elements that pass the test implemented by the provided function.
reduce()
Executes a reducer function on each element of the array, resulting in a single output value.
forEach()
Executes a provided function once for each array element.
find()
Returns the first element in the array that satisfies the provided testing function.
findIndex()
Returns the index of the first element in the array that satisfies the provided testing function.
some()
Tests whether at least one element in the array passes the test implemented by the provided function.
every()
Tests whether all elements in the array pass the test implemented by the provided function.
includes()
Determines whether an array includes a certain value among its entries.
indexOf()
Returns the first index at which a given element can be found in the array.
slice()
Returns a shallow copy of a portion of an array into a new array object.
splice()
Changes the contents of an array by removing or replacing existing elements and/or adding new elements.
concat()
Merges two or more arrays into a new array.
join()
Creates and returns a new string by concatenating all elements in an array.
reverse()
Reverses an array in place and returns the reference to the same array.
sort()
Sorts the elements of an array in place and returns the sorted array.
push()
Adds one or more elements to the end of an array and returns the new length.
pop()
Removes the last element from an array and returns that element.
shift()
Removes the first element from an array and returns that element.
unshift()
Adds one or more elements to the beginning of an array and returns the new length.
flat()
Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
flatMap()
Returns a new array formed by applying a given callback function to each element of the array, then flattening the result by one level.
fill()
Fills all the elements of an array from a start index to an end index with a static value.
Array.from()
Creates a new Array instance from an array-like or iterable object.
Array.isArray()
Determines whether the passed value is an Array.
📝 String (22)
split()
Divides a string into an ordered list of substrings by searching for a separator pattern, and returns them as a new array. The separator can be a plain string or a regular expression, and an optional limit caps how many pieces are returned. The original string is never modified, because JavaScript strings are immutable.
slice()
Extracts a section of a string between two indices and returns it as a brand-new string, leaving the original untouched. Negative indices count backwards from the end of the string, which makes it easy to grab suffixes such as file extensions. It is the most flexible and predictable of the substring-extraction methods.
substring()
Returns the part of a string between two indices, swapping the arguments automatically if the start is greater than the end, and treating negative or NaN indices as 0. The original string is never modified. It behaves like slice() for well-ordered, in-range arguments but differs in how it normalizes unusual ones.
toLowerCase()
Returns a new string with every character converted to lowercase using the Unicode default case mappings, leaving the original string unchanged. Characters that have no lowercase form, such as digits, punctuation, and unicameral scripts like Chinese or Korean, pass through untouched. For language-specific rules, use toLocaleLowerCase() instead.
toUpperCase()
Returns a new string with every character converted to uppercase according to the Unicode default case mappings; the original string is unchanged. Characters without an uppercase form pass through as-is, and a few mappings expand the string, most famously the German sharp s becoming SS. For language-specific behavior, use toLocaleUpperCase().
trim()
Returns a new string with whitespace removed from both ends, leaving the original string unchanged. Whitespace here means the full set the ECMAScript specification recognizes: spaces, tabs, line breaks, the no-break space, the byte-order mark, and the other Unicode space separators. Whitespace inside the string is never touched.
trimStart()
Returns a new string with whitespace removed only from the beginning, leaving the end and the interior untouched and the original string unchanged. It recognizes the same whitespace set as trim(), including tabs, line breaks, and Unicode space separators. The legacy alias trimLeft() refers to the same function.
trimEnd()
Returns a new string with whitespace removed only from the end, preserving all leading and interior whitespace, and leaving the original string unchanged. It recognizes the same whitespace set as trim(), including trailing newlines and carriage returns. The legacy alias trimRight() refers to the same function.
replace()
Returns a new string in which a pattern has been replaced: with a string pattern or a regular expression lacking the global flag, only the first match is replaced, while a regex with the g flag replaces every match. The replacement can be a literal string, which supports special $-patterns, or a function called for each match. The original string is never modified.
replaceAll()
Returns a new string with every occurrence of the search value replaced, whether the search value is a plain string or a global regular expression. Added in ES2021, it fixes the classic surprise of replace() by making all-occurrence replacement the default for string patterns, with no regex or g flag required. The original string is never modified.
includes()
Determines whether one string can be found inside another, returning true or false. The search is case-sensitive, compares UTF-16 code units, and can optionally begin at a given position. Introduced in ES2015, it expresses a yes-or-no containment question directly, where older code had to compare indexOf() against -1.
startsWith()
Determines whether a string begins with the characters of a given search string, returning true or false. An optional position argument treats the check as if the string started at that index, letting you test for a prefix at any known offset. The comparison is case-sensitive and literal, added in ES2015.
endsWith()
Determines whether a string ends with the characters of a given search string, returning true or false. An optional length argument makes the check behave as if the string were only that long, so you can test for a suffix at an interior boundary. The comparison is case-sensitive and literal, added in ES2015.
indexOf()
Returns the index of the first occurrence of a search value within a string, or -1 if it is not found, optionally starting the search at a given position. Indices count UTF-16 code units from zero, and the search is case-sensitive and literal. It is the classic workhorse for locating where in a string something sits.
charAt()
Returns a new string containing the single UTF-16 code unit at the given index, or an empty string when the index is out of range. With no argument it returns the first character. For characters beyond the Basic Multilingual Plane, such as emoji, it yields one half of a surrogate pair rather than the full symbol.
charCodeAt()
Returns the numeric UTF-16 code unit at the given index, an integer between 0 and 65535, or NaN when the index is out of range. For characters encoded as surrogate pairs, such as emoji, it returns one half of the pair; codePointAt() returns the full code point instead. It is the numeric counterpart of charAt().
concat()
Joins one or more strings onto the calling string and returns the combined result as a new string, leaving every input unchanged. Arguments that are not strings are converted to strings first. In modern code it is largely superseded by template literals and the + operator, which do the same job more readably.
repeat()
Returns a new string consisting of the original repeated a given number of times, with the count coerced to an integer. A count of zero yields an empty string, and a negative or infinite count throws a RangeError. Added in ES2015, it replaced a family of loop-and-append and array-join tricks.
padStart()
Pads the beginning of a string with another string, repeated and truncated as needed, until the result reaches a target length, then returns that new string. If the original already meets or exceeds the target length it is returned unchanged, never truncated. The default pad is a space; added in ES2017.
padEnd()
Pads the end of a string with another string, repeated and truncated as needed, until the result reaches a target length, then returns that new string. Input that already meets the target length is returned unchanged, never truncated. The default pad is a space; added in ES2017 alongside padStart().
match()
Retrieves the result of matching a string against a regular expression. With the global flag it returns an array of all matched substrings without capture-group detail; without it, it returns a single exec-style match array carrying the captured groups, the match index, and the input. When nothing matches, it returns null, not an empty array.
search()
Executes a regular-expression search and returns the index of the first match, or -1 when no match exists. It is the pattern-powered counterpart of indexOf(): the same answer shape, but the needle is a regex rather than a literal string. The global flag and lastIndex state of the regex are ignored, so it always searches from the start.
📦 Object (15)
Object.keys()
Returns an array of a given object's own enumerable string-keyed property names, in the same order a for...in loop would produce them but without walking the prototype chain. It is the standard way to turn an object's keys into an array you can iterate, filter, or map with the full array toolkit.
Object.values()
Returns an array of a given object's own enumerable string-keyed property values, in the same order that Object.keys() lists the keys. It lets you apply array methods like reduce(), filter(), and Math aggregations directly to the data stored in an object without caring about the key names.
Object.entries()
Returns an array of a given object's own enumerable string-keyed [key, value] pairs, in the same order as Object.keys(). It is the bridge between objects and array iteration, enabling destructuring loops, Map construction, and filter-then-rebuild transformations with Object.fromEntries().
Object.fromEntries()
Transforms a list of [key, value] pairs — from an array, a Map, URLSearchParams, or any iterable — into a new plain object. It is the inverse of Object.entries() and the final step of the filter-map-rebuild pattern for immutable object transformations.
Object.assign()
Copies all enumerable own properties (both string- and Symbol-keyed) from one or more source objects onto a target object and returns that same target. It performs a shallow merge: later sources overwrite earlier ones, and nested objects are copied by reference, not cloned.
Object.freeze()
Freezes an object in place and returns it: no properties can be added, removed, or reassigned, and existing property descriptors cannot be reconfigured. The freeze is shallow — nested objects referenced by the frozen object remain fully mutable unless frozen themselves.
Object.isFrozen()
Returns true if an object is frozen: non-extensible, with every own property non-configurable and every data property non-writable. Ordinary objects return false until Object.freeze() (or equivalent descriptor surgery) has been applied, and primitives passed to it simply return true.
Object.seal()
Seals an object and returns it: no properties can be added or removed, and existing properties become non-configurable, but their values remain writable. It sits between preventExtensions (loosest) and freeze (strictest) on the mutability spectrum — a fixed shape with changeable contents.
Object.isSealed()
Returns true if an object is sealed — non-extensible with every own property non-configurable — regardless of whether values are still writable. Frozen objects always report true here as well, since freezing implies sealing.
Object.create()
Creates a new object whose internal prototype is set to the object you pass — or to null for a completely prototype-free object — optionally defining properties via descriptors in the same call. It is the most direct way to control the prototype chain at creation time.
hasOwnProperty()
Returns true when the object itself defines the named property, ignoring anything inherited from the prototype chain. Inherited from Object.prototype, it is the classic way to distinguish an object's own data from prototype members — with Object.hasOwn() as its safer modern successor.
Object.getPrototypeOf()
Returns the internal prototype ([[Prototype]]) of an object — the object it delegates to when a property lookup misses — or null at the end of the chain. It is the standards-blessed replacement for the legacy __proto__ accessor.
Object.defineProperty()
Defines a new property on an object — or reconfigures an existing one — using a descriptor that controls its value, writability, enumerability, configurability, or getter/setter pair. It is the low-level primitive behind class accessors, non-enumerable methods, and most pre-Proxy reactivity systems.
Object.getOwnPropertyDescriptor()
Returns the full descriptor of an own property — its value or get/set functions plus the writable, enumerable, and configurable flags — or undefined when the object has no such own property. It is the inspection counterpart to Object.defineProperty().
Object.getOwnPropertyNames()
Returns an array of every own string-keyed property name — enumerable or not — of the given object. It sees the hidden properties that Object.keys() skips, stopping only at Symbol keys and inherited members.
🧮 Math (15)
Math.abs()
Returns the absolute value of a number: the value itself if it is positive or zero, and its negation if it is negative. The argument is coerced to a number first, so numeric strings work while non-numeric input yields NaN, and Math.abs(-0) returns 0.
Math.floor()
Returns the largest integer less than or equal to the given number, rounding toward negative infinity. For positive numbers it simply drops the fraction, but for negatives it moves away from zero: Math.floor(-4.2) is -5. The result is still a double, so it can exceed 32-bit integer range safely.
Math.ceil()
Returns the smallest integer greater than or equal to the given number, rounding toward positive infinity. Any fractional part pushes the value up to the next integer for positive numbers, while negatives move toward zero: Math.ceil(-4.7) is -4, and Math.ceil(-0.5) is -0.
Math.round()
Returns the value rounded to the nearest integer, with exact halves rounded toward positive infinity: Math.round(2.5) is 3, but Math.round(-2.5) is -2. This "half up toward +∞" rule differs from the half-to-even (banker's) rounding used in many financial and scientific contexts.
Math.trunc()
Returns the integer part of a number by removing all fractional digits, always rounding toward zero: Math.trunc(4.9) is 4 and Math.trunc(-4.9) is -4. Added in ES2015, it differs from Math.floor() only for negative inputs, and unlike bitwise tricks it works across the full double range.
Math.random()
Returns a pseudo-random floating-point number in the half-open range [0, 1): 0 is possible, 1 is not. The sequence comes from a fast, non-cryptographic generator (xorshift128+ in major engines) that cannot be seeded and must never be used for security purposes.
Math.max()
Returns the largest of zero or more numbers passed as separate arguments. With no arguments it returns -Infinity, and if any argument coerces to NaN the result is NaN. Arrays must be spread into it, which imposes a practical size limit tied to the engine's argument-count maximum.
Math.min()
Returns the smallest of zero or more numbers passed as separate arguments. With no arguments it returns Infinity, and any argument that coerces to NaN makes the result NaN. Like Math.max(), it takes separate arguments, so arrays are spread into it, with the same large-array limits.
Math.pow()
Returns the base raised to the exponent power, following IEEE 754 semantics: fractional, negative, and special-value exponents are all defined. Since ES2016 the ** operator computes the same result; Math.pow remains useful as a first-class function and in pre-ES2016 codebases. Note that a negative base with a non-integer exponent yields NaN.
Math.sqrt()
Returns the square root of a number. Negative inputs return NaN (JavaScript has no built-in complex numbers), Math.sqrt(-0) is -0, and Math.sqrt(Infinity) is Infinity. The result is the correctly rounded double nearest the true root, as IEEE 754 requires of this operation.
Math.cbrt()
Returns the cube root of a number, correctly handling negatives: Math.cbrt(-8) is -2, because every real number has exactly one real cube root. Added in ES2015, it fills the gap left by Math.pow(x, 1/3), which returns NaN for negative bases under IEEE 754 rules.
Math.sign()
Returns the sign of a number: 1 for positive values, -1 for negative values, 0 for +0, -0 for -0, and NaN for anything that fails numeric coercion. It answers "which direction" while discarding magnitude, and is the standard companion to Math.abs(), which does the opposite.
Math.sin()
Returns the sine of an angle given in radians, a value oscillating between -1 and 1. As the fundamental periodic function, it converts steadily increasing input (time, angle, position) into smooth back-and-forth motion. Inputs in degrees must be converted first: radians = degrees * Math.PI / 180.
Math.cos()
Returns the cosine of an angle given in radians, oscillating between -1 and 1 and starting at 1 when the angle is 0. It is the horizontal partner of Math.sin(): together they convert an angle into the x and y coordinates of a point on the unit circle.
Math.log()
Returns the natural logarithm (base e) of a number, the inverse of Math.exp(). Inputs must be positive: Math.log(0) is -Infinity, negative inputs return NaN, and Math.log(1) is exactly 0. For other bases, JavaScript provides Math.log10 and Math.log2, or the change-of-base formula.
📅 Date (15)
Date.now()
Returns the number of milliseconds elapsed since the ECMAScript epoch, January 1, 1970 00:00:00 UTC. It is a static method called directly on the Date constructor and returns a plain number, so no Date object is created. Because the value is always UTC-based, it is identical across time zones at any given instant.
Date.parse()
Parses a string representation of a date and returns the number of milliseconds since the UNIX epoch, or NaN when the string cannot be interpreted. Only the ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ and its shorter forms) is guaranteed by the ECMAScript specification; every other format is parsed in engine-specific, historically inconsistent ways.
getTime()
Returns the number of milliseconds between the Date object and January 1, 1970 00:00:00 UTC. It exposes the single internal number a Date actually stores, making it the canonical way to convert a Date into a comparable, serializable primitive. For an invalid Date it returns NaN rather than throwing.
getFullYear()
Returns the four-digit year of the date according to local time, such as 2026. It replaces the deprecated getYear(), which returned the year minus 1900. Because the result depends on the local time zone, the same Date instant can report different years on machines near a New Year boundary.
getMonth()
Returns the month of the date as a zero-based index according to local time: 0 for January through 11 for December. The zero-based convention exists so the value can index directly into arrays of month names, but it is the single most common source of off-by-one date bugs in JavaScript.
getDate()
Returns the day of the month, from 1 to 31, for the given date according to local time. Unlike getMonth(), this getter is one-based, matching how humans write dates. Paired with setDate(), it is also the standard tool for safe day-based date arithmetic.
getDay()
Returns the day of the week for the given date according to local time, as an integer from 0 (Sunday) to 6 (Saturday). The value indexes weekday-name arrays directly, but note that it differs from ISO 8601 numbering, where Monday is 1 and Sunday is 7.
getHours()
Returns the hour of the given date according to local time, as an integer from 0 to 23. The value follows the 24-hour clock, so midnight is 0 and 11 PM is 23. It reflects the runtime's local time zone, including any daylight saving offset in effect at that instant.
getMinutes()
Returns the minutes component of the given date according to local time, as an integer from 0 to 59. It reads only the minute field of the wall-clock breakdown; it is not a duration in minutes, nor does it include hours.
getSeconds()
Returns the seconds component of the given date according to local time, as an integer from 0 to 59. Like the other component getters it reads wall-clock digits, not elapsed time; ECMAScript time ignores leap seconds, so 60 never appears.
getMilliseconds()
Returns the milliseconds component of the given date according to local time, as an integer from 0 to 999. It exposes only the sub-second digits of the wall-clock breakdown; the full epoch-relative millisecond count comes from getTime() or Date.now() instead.
toISOString()
Returns a string representing the date in the ISO 8601 extended format YYYY-MM-DDTHH:mm:ss.sssZ, always expressed in UTC (the trailing Z). It is the standard serialization format for machine exchange, the same one JSON.stringify uses for Date values via toJSON(), and it throws a RangeError when called on an invalid Date.
toLocaleString()
Returns a language-sensitive string representation of the date and time, formatted according to the given locale and options, or the environment's defaults when omitted. It is the display-oriented counterpart to toISOString(), backed by the same CLDR locale data as Intl.DateTimeFormat.
toLocaleDateString()
Returns just the date portion of a Date as a language-sensitive string, using the given locale and options; time components are omitted. It accepts the same locales and options machinery as Intl.DateTimeFormat, restricted by default to day-level fields.
setFullYear()
Sets the year of a Date object according to local time, optionally setting the month and day in the same call, and returns the new timestamp in milliseconds. It mutates the Date in place, and out-of-range month or day values are normalized by rolling into adjacent months or years.
🔄 JSON (5)
JSON.parse()
Parses a JSON string and reconstructs the JavaScript value it describes — objects, arrays, strings, numbers, booleans, and null. An optional reviver function lets you transform each value as it is restored, for example turning ISO date strings back into Date objects.
JSON.stringify()
Converts a JavaScript value into its JSON text representation, optionally filtering properties with a replacer and pretty-printing with the space parameter. Values JSON cannot represent — functions, undefined, Symbols — are dropped or nulled according to fixed rules, and objects with a toJSON() method serialize as whatever that method returns.
JSON.stringify() with replacer
The replacer parameter of JSON.stringify() intercepts every key-value pair during serialization: return a different value to transform it, or undefined to omit the property entirely. Passing an array of property names instead acts as a whitelist of properties to keep at every level.
JSON.parse() with reviver
The reviver parameter of JSON.parse() runs on every key-value pair as the text is parsed, from the deepest leaves upward, letting you replace parsed values on the fly. It is the standard hook for restoring Dates, BigInts, Maps, and other types that JSON flattens into strings and arrays.
toJSON()
toJSON() is a serialization protocol: when JSON.stringify() encounters any object exposing this method, the method's return value is serialized in place of the object itself. Date implements it natively (producing ISO strings), and defining it on your own classes gives them a canonical, self-describing wire format.
⏳ Promise (10)
then()
Attaches callbacks for the resolution and/or rejection of the Promise.
catch()
Attaches a rejection handler callback to the promise.
finally()
Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected).
Promise.all()
Returns a single Promise that resolves when all of the promises in the iterable have resolved, or rejects when any promise rejects.
Promise.allSettled()
Returns a promise that resolves after all of the given promises have either fulfilled or rejected, with an array of objects describing each outcome.
Promise.race()
Returns a promise that fulfills or rejects as soon as one of the promises fulfills or rejects.
Promise.any()
Returns a promise that fulfills when any of the promises fulfills, or rejects if all of the promises reject.
new Promise()
Creates a new Promise object with an executor function that receives resolve and reject callbacks.
Promise.resolve()
Returns a Promise object that is resolved with the given value.
Promise.reject()
Returns a Promise object that is rejected with the given reason.