String in JavaScript

What is a String?

🙋 Need help? Ask an expert now!

Strings are something you have already been working with throughout the whole course, starting from the Hello World program. A string is a sequence of characters that can be enclosed in single or double quotes. String is a primitive data type, meaning it is copied and passed by value. String are also immutable, meaning every time a string is changed, a new string is created instead of changing the old string.

The code sample above show an example of two strings, one that is enclosed by double quotes and the other enclosed by single quotes. String variable declared in the global scope can be accessed anywhere else in the program without a double quote, like how str is used within the console.log() message. We will be working with string methods in the upcoming content, so make sure you understand each concept as you move through the chapter.

Edit Me on GitHub!

Application Question

Which of the following are valid string declarations?