Complete reference of built-in JavaScript methods and properties, grouped by object type, with syntax examples and return types.
| Method / Property | Description | Syntax Example | Returns |
|---|---|---|---|
| str.length | Returns the number of characters in a string. | str.length | num |
| str.charAt(i) | Returns the character at index i. | str.charAt(0) | str |
| str.charCodeAt(i) | Returns the UTF-16 code at index i. | str.charCodeAt(0) | num |
| String.fromCharCode(n) | Returns string from UTF-16 codes. e.g. 65 ? 'A' | String.fromCharCode(65) | str |
| str.indexOf(s) | First index of substring, or -1 if not found. | str.indexOf('hi') | num |
| str.lastIndexOf(s) | Last index of substring, or -1. | str.lastIndexOf('e') | num |
| str.includes(s) | Returns true if string contains substring. | str.includes('world') | bool |
| str.startsWith(s) | Returns true if string starts with given prefix. | str.startsWith('He') | bool |
| str.endsWith(s) | Returns true if string ends with given suffix. | str.endsWith('!') | bool |
| str.slice(start, end) | Extracts a section. Negative indexes allowed. | str.slice(0, 5) | str |
| str.substring(start, end) | Like slice, but no negative indices. | str.substring(1, 4) | str |
| str.toUpperCase() | Converts all characters to uppercase. | str.toUpperCase() | str |
| str.toLowerCase() | Converts all characters to lowercase. | str.toLowerCase() | str |
| str.trim() | Removes whitespace from both ends. | str.trim() | str |
| str.trimStart() | Removes leading whitespace. | str.trimStart() | str |
| str.trimEnd() | Removes trailing whitespace. | str.trimEnd() | str |
| str.padStart(len, fill) | Pads start with fill until length is met. | str.padStart(5, '0') | str |
| str.padEnd(len, fill) | Pads end with fill until length is met. | str.padEnd(10, '.') | str |
| str.repeat(n) | Returns string repeated n times. | str.repeat(3) | str |
| str.replace(s, r) | Replaces first match of s with r. r can be function. | str.replace('a', 'b') | str |
| str.replaceAll(s, r) | Replaces all matches. | str.replaceAll('a', 'b') | str |
| str.split(sep) | Splits string into an array by separator. | str.split(',') | arr |
| str.match(regex) | Returns array of regex matches. | str.match(/\d+/g) | arr |
| str.matchAll(regex) | Returns iterator of all regex matches. | [...str.matchAll(/\d+/g)] | obj |
| str.search(regex) | Returns index of first regex match, or -1. | str.search(/\d/) | num |
| str.at(i) | Returns char at index. Negative index allowed (-1 = last). | str.at(-1) | str |
| str.concat(s2) | Joins two strings. Prefer template literals. | str.concat(' world') | str |
| str.normalize(form) | Unicode normalization form. | str.normalize('NFC') | str |
| Method / Property | Description | Syntax Example | Returns |
|---|---|---|---|
| arr.length | Number of elements in the array. | arr.length | num |
| arr.push(item) | Adds items to end. Returns new length. | arr.push(1, 2) | num |
| arr.pop() | Removes and returns last element. | arr.pop() | any |
| arr.shift() | Removes and returns first element. | arr.shift() | any |
| arr.unshift(item) | Adds items to start. Returns new length. | arr.unshift(0) | num |
| arr.splice(i, n, ...items) | Removes n items at i, optionally inserts. Returns removed. | arr.splice(1, 1, 'new') | arr |
| arr.slice(start, end) | Returns a shallow copy of a portion. Non-mutating. | arr.slice(1, 3) | arr |
| arr.concat(arr2) | Returns new array with merged values. | arr.concat([4, 5]) | arr |
| arr.join(sep) | Joins all elements into a string. | arr.join(', ') | str |
| arr.reverse() | Reverses array in place. Mutates original. | arr.reverse() | arr |
| arr.sort(fn) | Sorts in place. Pass comparator for numbers. | arr.sort((a,b) => a-b) | arr |
| arr.indexOf(item) | First index of item, or -1. | arr.indexOf(3) | num |
| arr.lastIndexOf(item) | Last index of item, or -1. | arr.lastIndexOf(3) | num |
| arr.includes(item) | Returns true if array contains item. | arr.includes(5) | bool |
| arr.find(fn) | First element satisfying predicate, or undefined. | arr.find(x => x > 2) | any |
| arr.findIndex(fn) | Index of first element satisfying predicate, or -1. | arr.findIndex(x => x > 2) | num |
| arr.findLast(fn) | Last element satisfying predicate. | arr.findLast(x => x % 2 === 0) | any |
| arr.findLastIndex(fn) | Index of last satisfying element. | arr.findLastIndex(x => x > 2) | num |
| arr.forEach(fn) | Calls fn for each element. Returns undefined. | arr.forEach((x, i) => ...) | void |
| arr.map(fn) | Returns new array with fn applied to each element. | arr.map(x => x * 2) | arr |
| arr.filter(fn) | Returns new array with elements passing predicate. | arr.filter(x => x > 0) | arr |
| arr.reduce(fn, init) | Reduces array to a single value. | arr.reduce((acc, x) => acc + x, 0) | any |
| arr.reduceRight(fn, init) | reduce from right to left. | arr.reduceRight((acc, x) => acc + x) | any |
| arr.some(fn) | True if any element satisfies predicate. | arr.some(x => x > 5) | bool |
| arr.every(fn) | True if all elements satisfy predicate. | arr.every(x => x > 0) | bool |
| arr.flat(depth) | Flattens nested arrays up to given depth. | arr.flat(Infinity) | arr |
| arr.flatMap(fn) | map() + flat(1) combined. | arr.flatMap(x => [x, x*2]) | arr |
| arr.fill(val, start, end) | Fills portion of array with a value. | arr.fill(0, 1, 3) | arr |
| arr.copyWithin(t, s, e) | Copies part of array to another position. | arr.copyWithin(0, 2) | arr |
| arr.entries() | Returns iterator of [index, value] pairs. | for (let [i, v] of arr.entries()) | obj |
| arr.keys() | Returns iterator of indices. | for (let i of arr.keys()) | obj |
| arr.values() | Returns iterator of values. | for (let v of arr.values()) | obj |
| arr.at(i) | Access by index. Negative allowed. | arr.at(-1) | any |
| Array.from(iterable) | Creates array from iterable or array-like. | Array.from('abc') | arr |
| Array.of(...items) | Creates array from arguments. | Array.of(1, 2, 3) | arr |
| Array.isArray(val) | Returns true if value is an array. | Array.isArray([]) | bool |
| arr.toSorted(fn) | Non-mutating sort (ES2023). | arr.toSorted((a,b) => a-b) | arr |
| arr.toReversed() | Non-mutating reverse (ES2023). | arr.toReversed() | arr |
| arr.toSpliced(i, n) | Non-mutating splice (ES2023). | arr.toSpliced(1, 1) | arr |
| arr.with(i, val) | Returns new array with element at i replaced (ES2023). | arr.with(2, 'x') | arr |
| Method / Property | Description | Syntax Example | Returns |
|---|---|---|---|
| Object.keys(obj) | Returns array of own enumerable property keys. | Object.keys({a:1, b:2}) | arr |
| Object.values(obj) | Returns array of own enumerable property values. | Object.values({a:1, b:2}) | arr |
| Object.entries(obj) | Returns array of [key, value] pairs. | Object.entries(obj) | arr |
| Object.assign(target, ...src) | Copies enumerable own properties from sources to target. | Object.assign({}, a, b) | obj |
| Object.freeze(obj) | Makes object immutable (prevents changes). | Object.freeze(obj) | obj |
| Object.seal(obj) | Prevents adding/removing properties but allows modifying. | Object.seal(obj) | obj |
| Object.create(proto) | Creates object with specified prototype. | Object.create(SomeProto) | obj |
| Object.getPrototypeOf(obj) | Returns the prototype of an object. | Object.getPrototypeOf([]) | obj |
| Object.setPrototypeOf(obj, proto) | Sets object's prototype (avoid, use Object.create). | Object.setPrototypeOf(obj, proto) | obj |
| Object.defineProperty(obj, k, desc) | Defines/modifies property with descriptor. | Object.defineProperty(obj, 'x', {value:1}) | obj |
| Object.getOwnPropertyNames(obj) | All own property names (including non-enumerable). | Object.getOwnPropertyNames(obj) | arr |
| Object.is(a, b) | Strict equality. Handles NaN and +0/-0 correctly. | Object.is(NaN, NaN) | bool |
| Object.fromEntries(arr) | Creates object from [key, value] pairs. Inverse of entries(). | Object.fromEntries([['a', 1]]) | obj |
| Object.hasOwn(obj, key) | True if obj has own property key (ES2022). Prefer over hasOwnProperty. | Object.hasOwn(obj, 'id') | bool |
| structuredClone(val) | Deep clone of a value (ES2022 global). | structuredClone(obj) | any |
| Method / Property | Description | Syntax Example | Returns |
|---|---|---|---|
| Math.PI | p - 3.14159265358979 | Math.PI | num |
| Math.E | Euler's number - 2.718281828 | Math.E | num |
| Math.abs(x) | Absolute value. Math.abs(-5) ? 5 | Math.abs(-5) | num |
| Math.ceil(x) | Rounds up to nearest integer. | Math.ceil(4.1) | num |
| Math.floor(x) | Rounds down to nearest integer. | Math.floor(4.9) | num |
| Math.round(x) | Rounds to nearest integer (.5 rounds up). | Math.round(4.5) | num |
| Math.trunc(x) | Removes decimal part without rounding. | Math.trunc(-4.7) | num |
| Math.sign(x) | Returns -1, 0, or 1 based on sign. | Math.sign(-3) | num |
| Math.max(...args) | Returns largest argument. | Math.max(1, 5, 3) | num |
| Math.min(...args) | Returns smallest argument. | Math.min(1, 5, 3) | num |
| Math.pow(base, exp) | base raised to exp. Prefer ** operator. | Math.pow(2, 10) | num |
| Math.sqrt(x) | Square root. Math.sqrt(16) ? 4 | Math.sqrt(16) | num |
| Math.cbrt(x) | Cube root. Math.cbrt(27) ? 3 | Math.cbrt(27) | num |
| Math.log(x) | Natural logarithm (base e). | Math.log(Math.E) | num |
| Math.log2(x) | Base-2 logarithm. log2(8) ? 3 | Math.log2(8) | num |
| Math.log10(x) | Base-10 logarithm. log10(1000) ? 3 | Math.log10(1000) | num |
| Math.random() | Random float in [0, 1). Multiply for range. | Math.random() | num |
| Math.sin(x) | Sine (radians). | Math.sin(Math.PI / 2) | num |
| Math.cos(x) | Cosine (radians). | Math.cos(0) | num |
| Math.tan(x) | Tangent (radians). | Math.tan(0) | num |
| Math.hypot(...args) | Square root of sum of squares. | Math.hypot(3, 4) | num |
| Math.clz32(x) | Count leading zeros in 32-bit binary. | Math.clz32(1) | num |
| Math.imul(a, b) | 32-bit integer multiplication. | Math.imul(3, 4) | num |
| Math.fround(x) | Nearest 32-bit float. | Math.fround(1.337) | num |
| Method / Property | Description | Syntax Example | Returns |
|---|---|---|---|
| Number.isInteger(n) | True if value is integer (no fractional part). | Number.isInteger(4.0) | bool |
| Number.isFinite(n) | True if finite number (not NaN/Infinity). | Number.isFinite(Infinity) | bool |
| Number.isNaN(n) | True only for NaN. Safer than global isNaN. | Number.isNaN(NaN) | bool |
| Number.isSafeInteger(n) | True if in safe integer range (-2^53-1). | Number.isSafeInteger(2**53 - 1) | bool |
| Number.parseInt(str, radix) | Parses string to integer. | Number.parseInt('0xFF', 16) | num |
| Number.parseFloat(str) | Parses string to float. | Number.parseFloat('3.14px') | num |
| num.toFixed(d) | Returns string with d decimal places. | (3.14159).toFixed(2) | str |
| num.toPrecision(d) | d significant digits as string. | (0.0001234).toPrecision(3) | str |
| num.toString(radix) | Number to string in given base (2-36). | (255).toString(16) | str |
| num.toLocaleString() | Locale-formatted number string. | (1234567).toLocaleString() | str |
| Number.MAX_SAFE_INTEGER | 2^53 - 1 = 9007199254740991. | Number.MAX_SAFE_INTEGER | num |
| Number.MIN_SAFE_INTEGER | -(2^53 - 1) | Number.MIN_SAFE_INTEGER | num |
| Number.POSITIVE_INFINITY | Positive Infinity value. | Number.POSITIVE_INFINITY | num |
| Number.EPSILON | Smallest float difference - 2.22e-16. | Number.EPSILON | num |
| Method / Property | Description | Syntax Example | Returns |
|---|---|---|---|
| new Date() | Current date and time. | new Date() | obj |
| new Date(ms) | Date from milliseconds since Unix epoch. | new Date(0) | obj |
| new Date(str) | Date from ISO 8601 string. | new Date('2025-01-01') | obj |
| Date.now() | Current timestamp in milliseconds. | Date.now() | num |
| Date.parse(str) | Parses date string to ms. | Date.parse('2025-01-01') | num |
| d.getFullYear() | 4-digit year. | d.getFullYear() | num |
| d.getMonth() | Month (0-11). January=0! | d.getMonth() | num |
| d.getDate() | Day of month (1-31). | d.getDate() | num |
| d.getDay() | Day of week (0=Sunday, 6=Saturday). | d.getDay() | num |
| d.getHours() | Hour (0-23). | d.getHours() | num |
| d.getMinutes() | Minute (0-59). | d.getMinutes() | num |
| d.getSeconds() | Second (0-59). | d.getSeconds() | num |
| d.getMilliseconds() | Milliseconds (0-999). | d.getMilliseconds() | num |
| d.getTime() | Milliseconds since epoch. | d.getTime() | num |
| d.toISOString() | ISO 8601 format: '2025-01-01T00:00:00.000Z' | d.toISOString() | str |
| d.toLocaleDateString() | Locale-specific date string. | d.toLocaleDateString('en-US') | str |
| d.toLocaleTimeString() | Locale-specific time string. | d.toLocaleTimeString() | str |
| d.toLocaleString() | Locale-specific date and time. | d.toLocaleString('en-US') | str |
| d.setFullYear(y) | Sets year and returns new timestamp. | d.setFullYear(2030) | num |
| d.setMonth(m) | Sets month (0-11). | d.setMonth(0) | num |
| d.setDate(n) | Sets day of month. | d.setDate(15) | num |
| Intl.DateTimeFormat | Internationalized date formatting. | new Intl.DateTimeFormat('de-DE').format(d) | obj |
| Method / Property | Description | Syntax Example | Returns |
|---|---|---|---|
| new Promise((res, rej) => {}) | Creates a Promise. Call resolve/reject to settle. | new Promise((resolve, reject) => resolve(42)) | obj |
| Promise.resolve(val) | Returns a resolved Promise. | Promise.resolve(42) | obj |
| Promise.reject(err) | Returns a rejected Promise. | Promise.reject(new Error('fail')) | obj |
| Promise.all(arr) | Resolves when all resolve. Rejects on any rejection. | Promise.all([p1, p2]) | obj |
| Promise.allSettled(arr) | Resolves when all settle (fulfilled or rejected). | Promise.allSettled([p1, p2]) | obj |
| Promise.race(arr) | Resolves/rejects with the first settled promise. | Promise.race([p1, p2]) | obj |
| Promise.any(arr) | Resolves with first fulfilled. Rejects if all reject. | Promise.any([p1, p2]) | obj |
| p.then(fn) | Called on resolution. Returns new Promise (chainable). | p.then(val => ...).then(val => ...) | obj |
| p.catch(fn) | Called on rejection. Shorthand for .then(null, fn). | p.catch(err => ...) | obj |
| p.finally(fn) | Called on either settle, always. Good for cleanup. | p.finally(() => cleanup()) | obj |
| async function | Declares async function that returns a Promise. | async function fetchData() { ... } | obj |
| await expr | Pauses until Promise settles. Only inside async function. | const data = await fetch(url) | any |
| for await...of | Iterates over async iterables. | for await (const x of asyncIterable) | void |
| Method / Property | Description | Syntax Example | Returns |
|---|---|---|---|
| JSON.stringify(val, replacer, space) | Converts JS value to JSON string. | JSON.stringify({a:1}, null, 2) | str |
| JSON.parse(str, reviver) | Parses JSON string to JS value. | JSON.parse('{"a":1}') | any |
| Method / Property | Description | Syntax Example | Returns |
|---|---|---|---|
| parseInt(str, radix) | Parses string to integer. Stops at first non-numeric char. | parseInt('10px', 10) | num |
| parseFloat(str) | Parses string to float number. | parseFloat('3.14abc') | num |
| isNaN(val) | True if value is NaN (or converts to NaN). Prefer Number.isNaN. | isNaN('hello') | bool |
| isFinite(val) | False for Infinity, -Infinity, NaN. | isFinite(Infinity) | bool |
| encodeURIComponent(str) | Encodes URI component. Use for query params. | encodeURIComponent('hello world') | str |
| decodeURIComponent(str) | Decodes a URI component. | decodeURIComponent('hello%20world') | str |
| encodeURI(uri) | Encodes full URI. Preserves :/?#[] etc. | encodeURI('http://example.com/path name') | str |
| decodeURI(uri) | Decodes a URI. | decodeURI(encoded) | str |
| setTimeout(fn, ms) | Calls fn after delay. Returns timer ID. | setTimeout(() => alert('hi'), 1000) | num |
| setInterval(fn, ms) | Calls fn repeatedly every ms. Returns timer ID. | setInterval(tick, 1000) | num |
| clearTimeout(id) | Cancels a setTimeout. | clearTimeout(timerId) | void |
| clearInterval(id) | Cancels a setInterval. | clearInterval(intervalId) | void |
| queueMicrotask(fn) | Queues microtask (runs before next macrotask). | queueMicrotask(() => ...) | void |
| requestAnimationFrame(fn) | Calls fn before next repaint. Best for animations. | requestAnimationFrame(animate) | num |
| cancelAnimationFrame(id) | Cancels scheduled animation frame. | cancelAnimationFrame(rafId) | void |
| structuredClone(val) | Deep clone. Handles circular refs, Maps, Sets. | structuredClone(obj) | any |
| eval(str) | Evaluates JavaScript code string. AVOID - security risk. | eval('2 + 2') | any |
| typeof val | Returns type as string ('string', 'number', 'object', etc.). | typeof 'hello' | str |
| instanceof | Checks if object is an instance of a constructor. | [] instanceof Array | bool |
| Method / Property | Description | Syntax Example | Returns |
|---|---|---|---|
| document.querySelector(sel) | First element matching CSS selector. | document.querySelector('.btn') | obj |
| document.querySelectorAll(sel) | NodeList of all matching elements. | document.querySelectorAll('li') | obj |
| document.getElementById(id) | Element with specific ID (fast). | document.getElementById('header') | obj |
| document.getElementsByClassName(c) | Live HTMLCollection of elements with class. | document.getElementsByClassName('card') | obj |
| document.getElementsByTagName(t) | Live HTMLCollection by tag name. | document.getElementsByTagName('div') | obj |
| document.createElement(tag) | Creates a new HTML element. | document.createElement('div') | obj |
| el.appendChild(child) | Appends child at end of parent. | parent.appendChild(newEl) | obj |
| el.prepend(...nodes) | Inserts nodes at start of element. | el.prepend(newEl) | void |
| el.append(...nodes) | Inserts nodes at end. Accepts strings too. | el.append(newEl, text) | void |
| el.insertBefore(n, ref) | Inserts node before reference node. | parent.insertBefore(newEl, refEl) | obj |
| el.insertAdjacentHTML(pos, html) | insertAdjacentHTML positions: beforebegin, afterbegin, beforeend, afterend. | el.insertAdjacentHTML('beforeend', '<p>Hi</p>') | void |
| el.removeChild(child) | Removes child from parent. | parent.removeChild(child) | obj |
| el.remove() | Removes element itself from DOM. | el.remove() | void |
| el.replaceChild(new, old) | Replaces child node with another. | parent.replaceChild(newEl, oldEl) | obj |
| el.cloneNode(deep) | Clones element. true = deep clone with children. | el.cloneNode(true) | obj |
| el.setAttribute(name, val) | Sets attribute value. | el.setAttribute('class', 'active') | void |
| el.getAttribute(name) | Returns attribute value. | el.getAttribute('href') | str |
| el.removeAttribute(name) | Removes attribute. | el.removeAttribute('disabled') | void |
| el.hasAttribute(name) | True if element has given attribute. | el.hasAttribute('hidden') | bool |
| el.classList.add(...cls) | Adds class(es) to element. | el.classList.add('visible') | void |
| el.classList.remove(...cls) | Removes class(es). | el.classList.remove('hidden') | void |
| el.classList.toggle(cls) | Toggles class. Returns true if added. | el.classList.toggle('open') | bool |
| el.classList.contains(cls) | True if element has the class. | el.classList.contains('active') | bool |
| el.addEventListener(evt, fn) | Attaches event listener. | el.addEventListener('click', handler) | void |
| el.removeEventListener(evt, fn) | Removes event listener (same fn reference required). | el.removeEventListener('click', handler) | void |
| el.dispatchEvent(event) | Fires a synthetic event on the element. | el.dispatchEvent(new Event('click')) | bool |
| el.getBoundingClientRect() | Returns DOMRect (top, left, width, height, etc.). | el.getBoundingClientRect() | obj |
| el.scrollIntoView() | Scrolls element into the viewport. | el.scrollIntoView({behavior:'smooth'}) | void |
| el.closest(sel) | Traverses ancestors to find closest matching element. | el.closest('.container') | obj |
| el.matches(sel) | Tests if element matches CSS selector. | el.matches(':hover') | bool |
| el.innerHTML | Get/set HTML content. XSS risk - sanitize user input! | el.innerHTML = '<b>Hello</b>' | str |
| el.textContent | Get/set text content. Safe (no HTML parsing). | el.textContent = 'Hello' | str |
| el.innerText | Get/set visible text (respects CSS visibility). | el.innerText | str |
| el.style.property | Inline style. Use classList for class-based styling. | el.style.color = 'red' | str |
| window.getComputedStyle(el) | Returns computed CSS values. | getComputedStyle(el).fontSize | obj |
| document.createTextNode(text) | Creates a text node. | document.createTextNode('Hello') | obj |
| document.createDocumentFragment() | A lightweight container for batch DOM operations. | const frag = document.createDocumentFragment() | obj |