JavaScript Cheat Sheet

  1. Variables: Store data values.
  2. Function: Reusable blocks of code.
  3. Objects: Collection of key-value pairs.
  4. Arrays: Ordered lists of items.
  5. Loops: Repeat actions multiple times.
  6. Conditionals: Make decisions in code.
  7. ES6: New JavaScript features.
  8. Arrow Functions: Shorter function syntax.
  9. Promises: Handle asynchronous operations.
  10. Async / Await: Syntactic sugar for promises.
  11. DOM: Interface to interact with HTML elements.
  12. Event Listeners: React to user actions.
  13. Hoisting: Variable and function declarations moved to the top.
  14. Closures: Functions with preserved scope.
  15. Scope: Access to variables and functions.
  16. Callbacks: Functions passed as arguments.
  17. IIFE: Function that executes immediately.
  18. Prototype: Mechanism for object inheritance.
  19. Classes: Blueprint for creating objects.
  20. Modules: Reusable code units.
  21. Spread Operator: Expand arrays or objects.
  22. Destructuring: Extract values from arrays or objects.
  23. Template Literals: String interpolation with backticks.
  24. Type Coercion: Automatic type conversion.
  25. Strict Mode: Enforce stricter parsing and error handling. 
  26. Map: Object with key-value pairs.
  27. Set: Collection of unique values.
  28. WeakMap: Map with weakly held keys.
  29. WeakSet: Set with weakly held values.
  30. Symbol: Unique and immutable data type.
  31. Generators: Functions that can be paused and resumed.
  32. Proxy: Custom behavior for basic operations. 
  33. Reflect: Methods to interact with JavaScript objects.
  34. JSON: Format for storing and transporting data.
  35. Fetch API: Modern way to make HTTP requests.
  36. LocalStorage: Store data in the browser.
  37. SessionStrorage: Temporary storage in the browser.
  38. Web Workers: Run scripts in background threads.
  39. Promise.all: Wait for multiple promises. 
  40. Promise.race: Resolve with the first settled promise.
  41. BigInt: Large integer representation.
  42. Nullish Coalescing: Handle null or undefined values.
  43. Optional Chaining: Safe access to nested properties. 
  44. Intl: Internationalization API. 
  45. Error Handling: Manager errors in code.
  46. Event Bubbling: Event propagation through DOM. 
  47. Debouncing: Limit the rate of function execution.
  48. Throttling: Ensure function execution at set intervals.
  49. Memoization: Optimize function performance.
  50. Garbage Collection: Automatic memory management.

JavaScript Number Methods

  1. toFixed(): Formats a number to fixed decimal places.
    • Example: let num = 1.2345; num.toFixed(2); //”1.23”
  2. toString(): Converts a number to a string.
    • Example: let num=123; num.toString(); //”123”
  3. parseInt(): Parses a string to an integer.
    • Example: parseInt(“123”); //123
  4. parseFloat(): Parses a string to a floating-point number.
    • Example: parseFloat(“12.34”); // 12.34
  5. isNaN(): Check if a value is NaN (Not-a-Number).
    • Example: isNaN(“abc”); //true
  6. isInteger(): Checks if a value is an integer. 
    • Example: Number.isInteger(123); //true
  7. isFinite(): Checks if a value is a finite number.
    • Example: isFinite(123); // true
  8. toExponential(): Converts a number to exponential notation.
    • Example: let num = 123; num.toExponential(2); // “1.23e+2”
  9. toPrecision(): Formats a number to a specified length.
    • Example: let num = 123; num.toPrecisioin(2); // “1.2e+2”
  10. valueOf(): Returns the primitive value of a number.
    • Example: let num = 123; num.valueOf(); 123

JavaScript Object Methods

  1. keys(): Returns an array of an object’s keys.
    • Example: let obj = {a: 1}; Object.keys(obj); // [“a”]
  2. values(): Returns an array of an object’s values.
    • Example: let obj = {a: 1}; Object.values(obj); // [1]
  3. entries(): Returns an array of an object’s key-value pairs.
    • Example: let obj = {a: 1}; Object.entries(obj); // [[“a”,1]]
  4. assign(): Copies values of all properties from one or more objects.
    • Example: Object.assign({}, {a,1}, {b,2}); // {a: 1, b: 2}
  5. freeze(): Prevents modifications to an object properties.
    • Example: let obj = {a: 1}; Object.freeze(obj);
  6. seal(): Prevents adding or removing properties, but allows modification.
    • Example: let obj {a: 1}; Object.seal(obj);
  7. hasOwnProperty(): Checks if an object contains a specific property.
    • Example: let obj = {a: 1}; obj.hasOwnProperty(“a”); // true
  8. is(): Compares if two values are the same.
    • Example: Object.is(1,1); // true
  9. create(): Creates a new object with the specified prototype.
    • Example: let obj = Object.create({a: 1});
  10. fromEntries(): Creates an object from an array of key-value pairs.
    • Example: Object.fromEntries([[“a”, 1]]); // {a: 1}
       

JavaScript Array Methods

  1. push(): Adds elements to the end of an array.
    • Example: let arr = [1,2]; arr.push(3); // [1,2,3]
  2. pop(): Removes the last element from an array.
    • Example: let arr = [1,2]; arr.pop(); // [1,2]
  3. shift(): Removes the first element from an array.
    • Example: let arr = [1,2,3]; arr.shift(); [2,3]
  4. unshift(): Adds elements to the beginning of an array.
    • Example: let arr = [2,3]; arr.unshift(1); // [1,2,3]
  5. splice(): Adds/removes elements from an array.
    • Example: let arr = [1,2,3]; arr.splice(1,1); //[1,3]
  6. slice(): Returns a portion of an array.
    • Example: let arr = [1,2,3]; arr.slice(1); // [2,3]
  7. concat(): Merges two or more arrays.
    • Example: let arr1 = [1]; let arr2 = [2]; arr1.concat(arr2); // [1,2]
  8. indexOf(): Returns the first index of a value. 
    • Example:let arr = [1,2,3]; arr.indexOf(2); // 1
  9. includes(): Checks if an array contains a value. 
    • Example: let arr = [1,2,3]; arr.includes(2); // true
  10. forEach(): Executes a function on each array element.
    • Example: let arr = [1,2]; arr.forEach(x => console.log(x));
  11. map(): Creates a new array with the results of a function.
    • Example: let arr = [1,2]; arr.map(x => x*2); // [2,4]
  12. filter(): Creates a new array with elements that pass a test.
    • Example: let arr = [1,2,3]; arr.filter(x => x>2); // [2,3]
  13. reduce(): Reduces array to a single value using a function.
    • Example: let arr = [1,2]; arr.reduce((a,b) => a+b); // 2
  14. find(): Returns the first element that passes a test.
    • Example: let arr = [1,2,3]; arr.find(x => x>1); // 
  15. findIndex(): Return the index of the first element that passes a test.
    • Example: let arr = [1,2,3]; arr.findIndex(x => x>1); // 1
  16. sort():  Sorts array elements in place.
    • Example: let arr = [3,1,2]; arr.sort(); //[1,2,3]
  17. reverse(): Reverses the order of array elements.
    • Example: let arr = [1,2,3]; arr.reverse(); [3,2,1]
  18. join(): Joins array elements into a string.
    • Example: let arr = [1,2,3]; arr.join(‘-’); “1-2-3”
  19. every(): Checks if all elements pass a test.
    • Example: let arr = [1,2,3]; arr.every(x => x>0); // true
  20. some(): Checks if any element passes a test.
    • Example: let arr = [1,2,3]; arr.some(x => x>2); // true
       

JavaScript String Method

  1. charAt(): Returns the character at a specific index.
    • Example: let str = “abc”; str.charAt(1); // “b”
  2. concat(): Combines two or more strings.
    • Example: let str = “Hello”; str.concat(“ world”); // “Hello world”
  3. includes(): Check if a string contains a specific value.
    • Example: let str = “Hello”; str.includes(“ell); // true
  4. indexOf(): Returns the index of the first occurrence of a value.
    • Example: let str = “Hello”; str.indexOf(“e”); //2
  5. slice(): Extracts a part of a string.
    • Example: let str = “Hello”; str.slice(1,3); // “el”
  6. split(): Splits a string into an array of substrings.
    • Example: let str = “a,b,c”; str.split(“,”); // [“a”, “b”, “c”]
  7. toLowerCase(): Converts a string to lowercase.
    • Example: let str = “Hello”; str.toLowerCase(); // hello
  8. toUpperCase(): Converts a string to uppercase.
    • Example: let str = “hello”; str.toUpperCase(); //HELLO
  9. trim(): Removes whitespace from both ends of a string.
    • Example: let str = “ hello ”; str.trim(); // “hello”
  10. replace(): Replaces a substring with a new value.
    • Example: let str = “Hello”; str.repalce(“e”,”a”); // “Hallo”