Strings are used to store text and are enclosed in quotes.
A JavaScript string consists of zero or more characters enclosed within quotes.
let text = “John Doe”; |
You can use either single or double quotes:
let carName1 = “Volvo XC60”; // Double quotes let carName2 = ‘Volvo XC60’; // Single quotes |
NoteStrings created with single or double quotes function the same way; there is no difference between them. |
You can include quotes within a string as long as they don’t match the quotes used to enclose the string.
let answer1 = “It’s alright”; let answer2 = “He is called ‘Johnny'”; let answer3 = ‘He is called “Johnny”‘; |
Templates were introduced in ES6 (JavaScript 2015) and are strings enclosed in backticks (`This is a template string`).
They allow the use of both single and double quotes within the string.
let text = `He’s often called “Johnny”`; |
Note: Templates are not supported in Internet Explorer. |