Anthony Maximus

The Javascript Cheat Sheet

Objects

These are things like how a document is a thing



Object What It Represents Example Usage
📌 Core Objects (Fundamental Objects in JavaScript)
Object A general-purpose object that can store key-value pairs let user = { name: "Alice", age: 25 };
Array A list-like object that holds multiple values let fruits = ["apple", "banana", "cherry"];
Function A function is a special object that can be executed function greet() { console.log("Hello!"); }
📌 Browser Objects (Interacting with the Browser)
window Represents the entire browser window window.innerWidth (gets window width)
document Represents the webpage (DOM) document.title (gets page title)
navigator Contains information about the browser navigator.userAgent (gets browser details)
location Represents the URL of the page location.href (gets current URL)
history Controls browser history (back/forward navigation) history.back() (goes back a page)
console Allows debugging messages in the browser console console.log("Hello");
screen Provides information about the user's screen screen.width (gets screen width)
📌 DOM Objects (Manipulating the Webpage)
HTMLElement Represents any HTML element document.getElementById("box")
NodeList A list of DOM nodes (like an array, but read-only) document.querySelectorAll("p")
Event Represents an event (e.g., click, keypress) event.type (gets event type)
classList Manages an element's CSS classes element.classList.add("active")
📌 String, Number & Boolean Objects (Working with Data)
String Represents text data let str = "Hello"; str.length;
Number Represents numeric values let num = 42; num.toFixed(2);
Boolean Represents true/false values let isActive = true;
Math Provides mathematical functions Math.random() (generates a random number)
📌 Date & Time Objects
Date Represents date & time let now = new Date();
📌 Data Storage Objects
localStorage Stores data in the browser permanently localStorage.setItem("key", "value");
sessionStorage Stores data for the session (disappears when closed) sessionStorage.setItem("key", "value");
JSON Converts objects to and from JSON format JSON.stringify(obj); JSON.parse(str);
📌 Special Objects (Advanced Use Cases)
RegExp Represents a regular expression for pattern matching let regex = /abc/; regex.test("abcdef");
Promise Represents an async operation that may complete in the future fetch("url").then(response => response.json());
Set Stores unique values (no duplicates) let mySet = new Set([1,2,3,3]);
Map Stores key-value pairs with any type of key let myMap = new Map(); myMap.set("name", "Alice");
WeakSet Like Set, but holds weak references to objects let ws = new WeakSet(); ws.add(obj);
WeakMap Like Map, but holds weak references to keys let wm = new WeakMap(); wm.set(obj, "value");