Quotation marks in JavaScript

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

JavaScript allows you to use three types of quotation marks:

  • apostrophe
  • Double quotes
  • Backticks

The first two are basically the same:

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

There is almost no difference in using either. The only difference is that the quote character used to delimit the string must be escaped:

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

There are multiple style guides, and it is recommended to always use one style over another.

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

Since the introduction of backticks in ES6 in 2015, backticks are the newest member of JavaScript.

They have a unique feature: they allow multi-line strings.

Multi-line strings can also use regular strings, and use escape characters:

const multilineString = 'A string\non multiple lines'

Use backticks to avoid escape characters:

const multilineString = `A string
on multiple lines`

Not only that. you can use it${}syntax:

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

I will introduce backtick-driven strings (called template literals) in another article, More in-depth details.

Download mine for freeJavaScript beginner's manual


More js tutorials: