Skip to main content

JavaScript Strings

JavaScript Strings & String Methods is a core JavaScript concept covering master JavaScript strings, learn how to extract substrings, replace content, This topic is essential for academic learning, board exam preparation, and developing optimized real-world code.

JavaScript strings are for storing and manipulating text. They are written inside quotes (single or double).

Basic Usage

let carName1 = "Volvo XC60"; // Double quotes
let carName2 = 'Volvo XC60'; // Single quotes

String Length

The length property returns the number of characters in a string.

let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let length = text.length; // 26

String Methods

JavaScript has many built-in methods to work with strings (remember: strings are Immutable).

MethodDescription
slice(start, end)Extracts a part of a string.
substring(start, end)Similar to slice.
replace(old, new)Replaces a specified value with another.
toUpperCase()Converts to upper case.
toLowerCase()Converts to lower case.
trim()Removes whitespace from both sides.
charAt(index)Returns the character at a specific index.
includes(str)Returns true if the string contains str.
let text = "Please visit Microsoft!";
let newText = text.replace("Microsoft", "VishnuDigital");

Template Literals (ES6)

Template Literals use back-ticks (`) instead of quotes. They are the modern standard for handling complex strings.

1. Multiline Strings

let text = `This is a
multiline
string.`;

2. Interpolation (Variables in Strings)

let firstName = "John";
let lastName = "Doe";
let text = `Welcome ${firstName}, ${lastName}!`;
Backslash Escaping

If you need to use a quote inside a string of the same type, use the backslash \ escape character: let text = "We are the so-called \"Vikings\" from the north.";


← Back: Events | Next: Numbers & Math →

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir