Skip to content

Quotes in JavaScript

The Valley of Code

Your Web Development Manual

An overview of the quotes allowed in JavaScript and their unique features

JavaScript allows you to use 3 types of quotes:

The first 2 are essentially the same:

const test = 'test'
const bike = "bike"

There’s little to no difference in using one or the other. The only difference lies in having to escape the quote character you use to delimit the string:

const test = 'test'
const test = 'te\'st'
const test = 'te"st'
const test = "te\"st"
const test = "te'st"

There are various style guides that recommend always using one style vs the other.

I personally prefer single quotes all the time, and use double quotes only in HTML.

Backticks are a recent addition to JavaScript, since they were introduced with ES6 in 2015.

They have a unique feature: they allow multiline strings.

Multiline strings are also possible using regular strings, using escape characters:

const multilineString = 'A string\non multiple lines'

Using backticks, you can avoid using an escape character:

const multilineString = `A string
on multiple lines`

Not just that. You can interpolate variables using the ${} syntax:

const multilineString = `A string
on ${1+1} lines`

I cover backticks-powered strings (called template literals) in a separate article, that dives more into the nitty-gritty details.

β†’ Get my JavaScript Beginner's Handbook
β†’ Read my JavaScript Tutorials on The Valley of Code
β†’ Read my TypeScript Tutorial on The Valley of Code
  • THE VALLEY OF CODE (+ PRO), your web development manual
  • I wrote 15+ free coding BOOKS, download them here
  • SOLOPRENEUR LAND the missing MBA for wannabe solopreneurs craving a life with more freedom, control, fulfillment and purpose (summer 2024)