Sitemap
Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

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: 13

2. 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…

--

--

Aman Kumar
Aman Kumar

Written by Aman Kumar

A passionate individual with a thirst for knowledge and a drive to make a positive impact on the world. I embrace challenges as opportunities for growth.

Stackademic
Stackademic

Published in Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.