The JavaScript Cheatsheet
The JavaScript Cheatsheet
💠 Data Types
┣ 📋 `Number` : Represents numeric values (integers and floats).
┣ 📋 `String` : Represents textual data.
┣ 📋 `Boolean` : Represents true or false values.
┣ 📋 `Null` : Represents the intentional absence of any object
value.
┣ 📋 `Undefined` : Represents a variable that has been declared but
has not been assigned a value.
┗ 📋 `Object` : Represents a collection of key-value pairs.
💠 Operators
┣ ➕ `Arithmetic` : +, -, *, /, % (remainder).
┣ 📈 `Assignment` : =, +=, -=, *=, /=, %=
┣ 🔄 `Increment/Decrement` : ++, --
┣ ⚖️ `Comparison` : ==, ===, !=, !==, <, >, <=, >=
┣ ⚛️ `Logical` : && (AND), || (OR), ! (NOT)
┣ 🌟 `Ternary` : condition ? expr1 : expr2
💠 Control Flow
┣ 🔄 `if` : Executes a statement if a condition is true.
┣ 🔄 `else` : Executes a statement if the 'if' condition is false.
┣ 🔄 `else if` : Executes a statement if another 'if' condition is
true.
┣ 🔁 `for` : Loops through a block of code a specified number of
times.
💠 Functions
┣ 📑 `Function Declaration` : function functionName(parameters) {
... }
┣ 📑 `Function Expression` : const functionName =
function(parameters) { ... }
┣ 📑 `Arrow Function` : (parameters) => { ... }
┣ 📑 `Default Parameters` : function functionName(param =
defaultValue) { ... }
┣ 📑 `Rest Parameters` : function functionName(...args) { ... }
┣ 📑 `Immediately Invoked Function Expression (IIFE)` : (function()
{ ... })()
┗ 📑 `Higher-Order Functions` : Functions that take other functions
as arguments or return functions.
💠 Arrays
┣ 📚 `Creation` : const arr = [elem1, elem2, ...];
┣ 📚 `Accessing Elements` : arr[index]
┣ 📚 `Adding Elements` : arr.push(elem), arr.unshift(elem)
┣ 📚 `Removing Elements` : arr.pop(), arr.shift()
┣ 📚 `Slicing` : arr.slice(startIndex, endIndex)
┣ 📚 `Spreading` : const newArray = [...arr]
┣ 📚 `Iterating` : arr.forEach(callback), arr.map(callback),
arr.filter(callback)
┗ 📚 `Reducing` : arr.reduce(callback, initialValue)
💠 Strings
┣ 📝 `Length` : str.length
┣ 📝 `Indexing` : str[index]
┣ 📝 `Substring` : str.substring(startIndex, endIndex)
┣ 📝 `Split` : str.split(separator)
┣ 📝 `Trim` : str.trim()
┣ 📝 `Concatenate` : str.concat(str1, str2, ...)
┗ 📝 `Template Literal` : `Hello, ${name}!`
💠 Error Handling
┣ 🔍 `try...catch` : Catches errors in a block of code.
┣ 🔍 `throw` : Throws a custom error.
┗ 🔍 `Error Object` : new Error('Error message')
💠 Event Handling
┣ 🎉 `addEventListener` : Attaches an event handler to an element.
┣ 🎉 `Event Object` : Contains information about the event.
┣ 🎉 `Event Propagation` : Bubbling & Capturing.
┗ 🎉 `Preventing Default` : event.preventDefault()
💠 DOM Manipulation
┣ 🖌️ `getElementById` : Retrieves an element by its id.
┣ 🖌️ `getElementsByClassName` : Retrieves elements by their class
name.
┣ 🖌️ `getElementsByTagName` : Retrieves elements by their tag name.
💠 Local Storage
┣ 💾 `setItem` : Stores data in local storage.
┣ 💾 `getItem` : Retrieves data from local storage.
┗ 💾 `removeItem` : Removes data from local storage.
💠 Web APIs
┣ 🌍 `Geolocation API` : Retrieves the user's geographic location.
┣ 🌍 `Notification API` : Displays desktop notifications.
┣ 🌍 `Canvas API` : Draws graphics on a web page.
┣ 🌍 `Audio & Video API` : Controls audio and video playback.
┣ 🌍 `WebSockets API` : Enables real-time communication between
clients and servers.
┗ 🌍 `Service Workers` : Enables progressive web app features like
offline support.
💠 Unit Testing
┣ 🧪 `Jest` : A popular JavaScript testing framework.
┣ 🧪 `describe` : Groups test cases.
┣ 🧪 `it` : Defines a test case.
┣ 🧪 `expect` : Defines assertions for test validation.
┗ 🧪 `mock` : Creates mock functions and modules for testing.