ABOUT CONTACT
Prev Page Next Page
Top

JavaScript Strings

➢JavaScript strings are for storing and manipulating text.

EXAMPLE:

let Name1 = "Sanvi"; // Using double quotes
let Name2 = 'Sanvi'; // Using single quotes

EXAMPLE:

let x = "It's alright"; // Single quote inside double quotes
let y = "He is called 'joshik'"; // Single quotes inside double quotes
let y = 'He is called "joshik"'; // Double quotes inside single quotes

String Length

➢To find the length of a string, use the built-in length property:

EXAMPLE:

let Name = "Manu";
let length = Name.length

Escape Character

➢Because strings must be written within quotes, JavaScript will misunderstand this string:

EXAMPLE:

let Name = "We welcome you"to"BMR EDUCATIOn";

➢The string will be chopped to "We are the so-called ".
➢The solution to avoid this problem, is to use the backslash escape character.
➢The backslash (\) escape character turns special characters into string characters:

Code Result Description
\' ' Single quote
\" " Double quote
\\ \ Backslash

EXAMPLE:

let Name = "We welcome you \"to\" BMR EDUCATION";

EXAMPLE:

let text = 'It\'s alright.';

EXAMPLE:

let text = "We welcome you to \\ BMR EDUCATION";

Code Result
\b Backspace
\f Form Feed
\n New Line
\r Carriage Return
\t Horizontal Tabulator
\v Vertical Tabulator

Prev Page Next Page





FEEDBACK

Rating


Message