String Basics

Working with text strings.

Examples

String Quotes

Both single and double quotes work the same way.

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

Quotes Inside String

Using quotes inside a string.

let answer1 = "It's alright";
let answer2 = "He is called 'Johnny'";
let answer3 = 'He is called "Johnny"';

String as Object

Comparing string literals vs string objects.

let x = "John";
let y = new String("John");
console.log(typeof x); // string
console.log(typeof y); // object

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.