๐จ JavaScript Dictionary
Every keyword, operator, and symbol โ with plain-English explanations.
!== operatorStrict inequality: true when value or type differ.
if (a !== b) {}... operatorSpread/rest: expands an iterable into individual items, or gathers into array.
const copy = [...arr]; function f(...args) {}?. operatorOptional chaining: safely reads a property without throwing if left side is null.
user?.address?.city
?? operatorNullish coalescing: returns right side only if left is null or undefined.
const name = user.name ?? 'Guest'
Array.every methodReturns true if all elements pass the test.
arr.every(x => x > 0)
Array.filter methodCreates a new array with only elements that pass the test function.
[1,2,3,4].filter(x => x % 2 === 0) // [2,4]
Array.find methodReturns the first element that passes the test, or undefined.
users.find(u => u.id === 5)
Array.flat methodFlattens nested arrays by the given depth (default 1).
[[1,2],[3]].flat() // [1,2,3]
Array.forEach methodCalls a function for each element โ no return value.
arr.forEach(x => console.log(x))
Array.from methodCreates an array from an iterable or array-like object.
Array.from('hello') // ['h','e','l','l','o']Array.includes methodReturns true if the array contains the given value.
[1,2,3].includes(2) // true
Array.join methodJoins all elements into a string with the given separator.
arr.join(', ')Array.map methodCreates a new array by applying a function to each element.
[1,2,3].map(x => x * 2) // [2,4,6]
Array.pop methodRemoves and returns the last element of an array.
const last = arr.pop()
Array.push methodAdds one or more elements to the end of an array and returns new length.
arr.push(4)
Array.reduce methodReduces an array to a single value by applying a function to each element.
[1,2,3].reduce((acc, x) => acc + x, 0) // 6
Array.shift methodRemoves and returns the first element of an array.
const first = arr.shift()
Array.slice methodReturns a shallow copy of a portion of the array without modifying original.
arr.slice(1, 3)
Array.some methodReturns true if at least one element passes the test.
arr.some(x => x > 10)
Array.sort methodSorts the array in place. Pass a comparator for numeric sort.
arr.sort((a, b) => a - b)
Array.splice methodInserts, removes, or replaces elements in place at a given index.
arr.splice(2, 1, 'new')
Array.unshift methodAdds elements to the beginning of an array.
arr.unshift(0)
JSON.stringify globalConverts a JavaScript value to a JSON string.
JSON.stringify({a:1}) // '{"a":1}'Object.assign methodCopies properties from source objects into a target object.
Object.assign(target, source)
Object.entries methodReturns an array of [key, value] pairs for own enumerable properties.
Object.entries(obj).forEach(([k,v]) => {})Object.freeze methodMakes an object immutable โ no properties can be added, removed, or changed.
const o = Object.freeze({x:1})Object.keys methodReturns an array of an object's own enumerable property names.
Object.keys({a:1, b:2}) // ['a','b']Object.values methodReturns an array of an object's own enumerable property values.
Object.values({a:1, b:2}) // [1,2]Promise.all methodResolves when all promises resolve, or rejects when any rejects.
const results = await Promise.all([p1, p2])
Promise.race methodSettles as soon as the first promise in the array settles.
const first = await Promise.race([p1, p2])
String.endsWith methodReturns true if the string ends with the given suffix.
'file.js'.endsWith('.js')String.includes methodReturns true if the string contains the given substring.
'hello world'.includes('world')String.padStart methodPads the start of a string to reach a target length.
'5'.padStart(3, '0') // '005'
String.replace methodReplaces the first match of a pattern with a replacement string.
'hello'.replace('l', 'r') // 'herlo'String.slice methodExtracts part of a string, returning a new string.
'hello'.slice(1, 3) // 'el'
String.split methodSplits a string into an array of substrings using a separator.
'a,b,c'.split(',') // ['a','b','c']String.startsWith methodReturns true if the string begins with the given prefix.
'https://'.startsWith('https')String.toLowerCase methodReturns the string converted to all lowercase.
'HELLO'.toLowerCase() // 'hello'
String.toUpperCase methodReturns the string converted to all uppercase.
'hello'.toUpperCase() // 'HELLO'
String.trim methodRemoves leading and trailing whitespace from a string.
' hi '.trim() // 'hi'
addEventListener DOMAttaches an event handler to an element for a specified event type.
btn.addEventListener('click', handler)async keywordMarks a function as asynchronous โ it always returns a Promise.
async function fetchData() { }at JAVASCRIPT ARRAY METHODSReturns the value of the element at the specified index or undefined if the index is out of range.
[].at(0)
await keywordPauses an async function until a Promise resolves, then returns its value.
const data = await fetch(url).then(r => r.json())
break keywordExits the nearest enclosing loop or switch statement.
for (...) { if (done) break }case keywordA branch label inside a switch statement.
case 'error': handleError(); break
catch keywordHandles errors thrown in the corresponding try block.
catch (e) { console.error(e.message) }class keywordDefines an ES6 class with constructor, methods, and optional inheritance.
class Animal { constructor(name) { this.name = name } }classList DOMProvides methods to add, remove, toggle, and check CSS classes.
el.classList.add('active')clearInterval globalCancels an interval created by setInterval.
clearInterval(id)
clearTimeout globalCancels a timeout created by setTimeout.
clearTimeout(id)
console.error globalPrints an error message to the console (shown in red in browsers).
console.error('failed:', err)console.table globalDisplays an array or object as a formatted table in the console.
console.table(users)
console.warn globalPrints a warning message to the console.
console.warn('deprecated function')continue keywordSkips the rest of the current loop iteration.
for (...) { if (skip) continue }default keywordThe fallback branch of a switch when no case matches.
default: console.log('unknown')delete operatorRemoves a property from an object.
delete obj.key
do keywordRuns a loop body at least once, then repeats while the condition is true.
do { x++ } while (x < 10)document.getElementById DOMReturns the element with the given id, or null if not found.
const btn = document.getElementById('submit')document.querySelector DOMReturns the first element matching a CSS selector.
const el = document.querySelector('.active')document.querySelectorAll DOMReturns all elements matching a CSS selector as a NodeList.
document.querySelectorAll('li').forEach(el => {})else keywordThe branch that runs when an if condition is false.
if (x) {} else { doDefault() }export keywordMakes a binding available to other modules.
export function add(a, b) { return a + b }extends keywordCreates a subclass that inherits from a parent class.
class Dog extends Animal { bark() { } }finally keywordRuns cleanup code after try/catch regardless of whether an error occurred.
finally { cleanup() }for keywordClassic counted loop: initializer; condition; increment.
for (let i = 0; i < 10; i++) {}if keywordExecutes a block when its condition is true.
if (x > 0) { console.log('positive') }import keywordImports bindings from another ES module.
import { add } from './math.js'in operatorReturns true if a property name exists in an object.
'length' in []
includes JAVASCRIPT ARRAY METHODSReturns a boolean indicating whether the array includes a certain value.
[1, 2, 3].includes(2)
indexOf JAVASCRIPT ARRAY METHODSReturns the first index at which a given element can be found in the array, or -1 if it is not present.
[1, 2, 3].indexOf(2)
innerHTML DOMGets or sets the HTML content inside an element.
el.innerHTML = '<b>updated</b>'
instanceof operatorChecks whether an object was created by a given constructor.
if (err instanceof TypeError) { }isArray JAVASCRIPT ARRAY METHODSReturns true if the specified value is an Array.
Array.isArray([1, 2, 3])
join JAVASCRIPT ARRAY METHODSJoins all elements of an array into a string.
[1, 2, 3].join(',')keys JAVASCRIPT ARRAY METHODSReturns an ArrayIterator object that contains the keys (indices) of each index in the array.
[1, 2, 3].keys().next().value$,
lastIndexOf JAVASCRIPT ARRAY METHODSReturns the index of the last occurrence of a specified value in an array.
[1, 2, 3, 2, 1].lastIndexOf(2)
length JAVASCRIPT ARRAY METHODSReturns the number of elements in an array.
[1, 2, 3].length$,
map JAVASCRIPT ARRAY METHODSCreates a new array with the results of calling a provided function on every element in the calling array.
[1, 2, 3].map(x => x * 2)
new keywordCreates an instance of a class or constructor function.
const dog = new Dog('Rex')return keywordExits a function, optionally returning a value to the caller.
return result
setInterval globalCalls a function repeatedly at a fixed interval in milliseconds.
const id = setInterval(tick, 500)
setTimeout globalCalls a function once after a specified delay in milliseconds.
setTimeout(() => doWork(), 1000)
switch keywordCompares a value against multiple cases and runs the matching branch.
switch(day) { case 'Mon': work(); break }template literal syntaxString delimited by backticks allowing embedded expressions with ${} syntax.
const msg = `Hello, ${name}!`textContent DOMGets or sets the plain text content of an element (no HTML parsing).
el.textContent = 'Hello'
this keywordRefers to the current execution context โ the object the method was called on.
this.name = name
throw keywordThrows an exception, transferring control to the nearest catch block.
throw new Error('invalid input')try keywordWraps code that might throw an error. Paired with catch and/or finally.
try { riskyOp() } catch (e) { handle(e) }typeof operatorReturns a string describing the type of its operand.
typeof 42 // 'number'
var keywordDeclares a function-scoped variable. Prefer let or const in modern JS.
var x = 5
void operatorEvaluates an expression and returns undefined.
void someCall()
while keywordLoops as long as a condition remains true.
while (queue.length > 0) { process(queue.shift()) }concat JAVASCRIPT ARRAY METHODSConcatenates two or more arrays and returns a new array.
[1, 2].concat([3, 4])
let keywordBlock-scoped variable that can be reassigned.
let x = 5;
const keywordBlock-scoped constant that cannot be reassigned.
const PI = 3.14;
copyWithin JAVASCRIPT ARRAY METHODSCopies a portion of an array to another location in the same array and returns the modified array.
[1, 2, 3, 4, 5].copyWithin(0, 3, 5)
entries JAVASCRIPT ARRAY METHODSReturns a new Array Iterator object that contains the key-value pairs for each index in the array.
[1, 2, 3].entries().next().value$,
function keywordDeclares a named function.
function greet(name) { return name; }=> operatorArrow function โ shorter syntax, no own this binding.
const add = (a, b) => a + b;
every JAVASCRIPT ARRAY METHODSTests whether all elements in the array pass the test implemented by the provided function.
[1, 2, 3].every(num => num > 0)
async/await keywordMarks function async; await pauses until Promise resolves.
const data = await fetch(url);
fill JAVASCRIPT ARRAY METHODSFills the elements of an array with a static value, from a start index (inclusively) to an end index (exclusively).
[1, 2, 3, 4, 5].fill(0, 1, 4)
=== operatorStrict equality โ checks value AND type.
5 === 5
filter JAVASCRIPT ARRAY METHODSReturns a new array with all elements that pass the test implemented by the provided function.
[1, 2, 3, 4, 5].filter(num => num % 2 === 0)
console.log functionPrints to browser or Node.js console.
console.log(x);
find JAVASCRIPT ARRAY METHODSReturns the value of the first element in the array that passes the test implemented by the provided function.
[1, 2, 3, 4, 5].find(num => num > 2)
fetch functionMakes HTTP request, returns Promise.
const res = await fetch("/api");findIndex JAVASCRIPT ARRAY METHODSReturns the index of the first element in the array that passes the test implemented by the provided function, or -1 if no such element is found.
[1, 2, 3, 4, 5].findIndex(num => num > 2)
JSON.parse functionParses JSON string to JS object.
const obj = JSON.parse(str);
findLast JAVASCRIPT ARRAY METHODSReturns the value of the last element in the array that passes the test implemented by the provided function.
[1, 2, 3, 4, 5].findLast(num => num > 2)
Promise classRepresents eventual completion of async operation.
new Promise((res, rej) => {})findLastIndex JAVASCRIPT ARRAY METHODSReturns the index of the last element in the array that passes the test implemented by the provided function, or -1 if no such element is found.
[1, 2, 3, 4, 5].findLastIndex(num => num > 2)
flat JAVASCRIPT ARRAY METHODSFlattens an array by the specified depth.
[[1, 2], [3, 4]].flat(2)
flatMap JAVASCRIPT ARRAY METHODSMutates an array by applying a function to each of its elements and flattening the result into a new array.
[1, 2, 3, 4, 5].flatMap(num => [num, num * 2])
forEach JAVASCRIPT ARRAY METHODSInvokes a provided function once for each array element.
[1, 2, 3, 4, 5].forEach(num => console.log(num))
from JAVASCRIPT ARRAY METHODSCreates an array from an array-like or iterable object.
Array.from('Hello')fromAsync JAVASCRIPT ARRAY METHODSCreates an array from an iterable object or a function that asynchronously returns an iterable object.
Array.fromAsync(asyncIterable)