26 November 2024

Lesson 5 Async JavaScript | Promise | String Methods

Event Loop

Video: Event Loop in JavaScript

Promises

Article: Promises

Async JavaScript

Article for just look through: async javascript

JavaScript string methods

  • charAt(index) - Returns the character at the specified index.

    • Example:
      "hello".charAt(1); // "e"
      
  • concat(...strings) - Combines the original string with one or more strings and returns the result.

    • Example:
      "hello".concat(" ", "world"); // "hello world"
      
  • includes(substring, start) - Checks if a string contains a specified substring, starting at an optional position.

    • Example:
      "hello world".includes("world"); // true
      
  • indexOf(substring, start) - Returns the index of the first occurrence of a substring, or -1 if not found.

    • Example:
      "hello world".indexOf("o"); // 4
      
  • lastIndexOf(substring, start) - Returns the index of the last occurrence of a substring, or -1 if not found.

    • Example:
      "hello world".lastIndexOf("o"); // 7
      
  • slice(start, end) - Extracts a section of the string and returns it as a new string.

    • Example:
      "hello world".slice(0, 5); // "hello"
      
  • substring(start, end) - Returns the part of the string between the start and end indices.

    • Example:
      "hello world".substring(0, 5); // "hello"
      
  • toLowerCase() - Converts the string to lowercase.

    • Example:
      "Hello World".toLowerCase(); // "hello world"
      
  • toUpperCase() - Converts the string to uppercase.

    • Example:
      "Hello World".toUpperCase(); // "HELLO WORLD"
      
  • trim() - Removes whitespace from both ends of the string.

    • Example:
      "  hello world  ".trim(); // "hello world"
      
  • split(separator, limit) - Splits a string into an array of substrings based on a separator.

    • Example:
      "hello world".split(" "); // ["hello", "world"]
      
  • replace(searchValue, newValue) - Replaces occurrences of a substring with a new string.

    • Example:
      "hello world".replace("world", "everyone"); // "hello everyone"
      
  • replaceAll(searchValue, newValue) - Replaces all occurrences of a substring with a new string.

    • Example:
      "hello world world".replaceAll("world", "everyone"); // "hello everyone everyone"
      
  • startsWith(substring, start) - Checks if the string starts with the specified substring.

    • Example:
      "hello world".startsWith("hello"); // true
      
  • endsWith(substring, length) - Checks if the string ends with the specified substring.

    • Example:
      "hello world".endsWith("world"); // true
      
  • repeat(count) - Repeats the string the specified number of times.

    • Example:
      "hello".repeat(3); // "hellohellohello"
      
  • padStart(targetLength, padString) - Pads the string at the start with the specified string until it reaches the target length.

    • Example:
      "5".padStart(3, "0"); // "005"
      
  • padEnd(targetLength, padString) - Pads the string at the end with the specified string until it reaches the target length.

    • Example:
      "5".padEnd(3, "0"); // "500"