JavaScript Shortcuts

Boost your productivity with these essential JavaScript shortcuts.

ShortcutDescription
console.logLog output to the console
document.querySelectorSelect an element from the DOM
document.getElementByIdGet an element by its ID
addEventListenerAttach an event handler
setTimeoutExecute a function after a delay
setIntervalExecute a function repeatedly with a delay
JSON.stringifyConvert an object to JSON string
JSON.parseParse a JSON string into an object
Array.mapApply a function to each array element
Array.filterFilter array elements
Array.reduceReduce an array to a single value
Array.forEachExecute a function for each array element
Math.randomGenerate a random number
Math.floorRound a number down
localStorage.setItemSave data to local storage
localStorage.getItemRetrieve data from local storage
Promise.thenHandle a resolved promise
Promise.catchHandle a rejected promise
async/awaitWork with asynchronous code in a cleaner way
fetchMake HTTP requests