Member-only story
Essential JavaScript String Methods and Functions
In JavaScript, a string is a sequence of characters enclosed within single (‘’), double (“”) or backtick (``) quotes. Strings are used to represent and manipulate textual data in JavaScript. They can contain letters, numbers, symbols, and whitespace characters.
For example:
let str1 = 'Hello';
let str2 = "World";
let str3 = `JavaScript`;Strings in JavaScript are immutable, meaning once a string is created, it cannot be changed. However, you can create a new string based on modifications of an existing string.
JavaScript provides a variety of methods and functions for working with strings, which are sequences of characters. Here’s an overview of some commonly used methods and functions:
1. String Length:-
— length: Returns the length of a string.
const str = "Hello, World!";
console.log(str.length); // Output: 132. Accessing Characters:-
— Strings can be accessed character by character using bracket notation or the charAt() method.
const str = "Hello";
console.log(str[0]); // Output: "H"
console.log(str.charAt(1)); // Output: "e"3. Substring:-
— substring(startIndex, endIndex): Returns the substring starting from startIndex to endIndex — 1.
const str = "Hello, World!";
console.log(str.substring(7, 12)); // Output…








