Select Page
Javascript strings are very similar to python, with some differences.

You can use single or double quotes, and you also can use backticks. Backticks are a great way to enclose strings that have both single and double quotes in them, as anything in a backtick is allowed and you don’t have to \ it out.

Examples of Javascript Strings:

‘My name is Mike’
“My name is Mike’

`My Name’s “Mike”` – this would output: My Name’s “Mike”

Another reason to use backticks is because you can use string interpolation. What I mean by this is, let’s say you declare a variable and want to use that variable in a string:
const name = ‘Mike’

Now, you can use that variable in a string by using backticks:
`Hello, my name is ${name}.`

You can’t use a variable in a string unless you use backticks.

Another example:
`Hello, I am {20 + 25} years old. `
This would output Hello, I am 45 years old.

Using backticks is also the best way to do multiple line strings, as such:

let favoriteFood = `I
it is my
favorite food`;

This is the cleanest way to do multiple line strings.

Hopefully this explains strings in javascript.