Using strings in JavaScript
Strings are primitive values. They are a sequence of characters. There are three ways to create strings in JavaScript: using single quotes, '
, double quotes, "
, or backticks, `
.
console.log('Hello World'); console.log("Hello World"); console.log(`Hello World`);
Strings are immutable, which means that once they are created, they cannot be modified, but you can overwrite the variables or references depending on the data structure. So, all the methods that you use to modify a string will return a new string (or array):
Template strings allow you to use placeholders, ${}
, to insert variables or expressions inside a string. There is also added support for multiple lines:
const name = "John"; console.log(`Hello ${name}!`) //Hello John!
Important methods
There are many ways to perform operations with strings, but in this section, we will see only the most important methods that you will use in your day-to...