📒
SDV503
  • SDV503
  • Command Prompt
    • Windows Command Prompt
    • Mac OS Terminal
  • GIT & GITHub
    • GitHub
    • Git
      • Git Workflow
        • Forking Workflow
  • README
    • How to write a readme.md file?
    • Write a better README.me
    • Generate a README for GitHub Repo Quickly
  • Code-comments
    • Clean Comments
    • Writing Comments in a Good way
  • Pair Coding
    • What is Pair Coding?
    • Pair Programming Experience
  • Programming?
    • What is Programming?
    • What Is A Programming Paradigm?
    • JavaScript Programming Paradigms
  • Number Systems
    • Decimal and Binary numbers
  • JavaSCript
    • Introduction To JavaScript
      • The JavaScript Engine
  • JS Call Stack
    • JavaScript call stack
    • JavaScript & Memory
      • Memory Leaks in JavaScript
    • Execution Context and Execution Stack in Javascript
      • Javascript Execution Context and Hoisting
  • JavaScript Variables
    • Introduction to JS Data Types
    • Primitive and Non-Primitive
    • Operator precedence and associativity
      • JS Operators Part One
      • JS Operators Part Two
      • JS Operators Part Three
    • Clean Code for JS Variables
  • JavaScript Scopes
    • Scope (Chain) Visualized
  • Javascript  — this keyword
  • JavaScript Data Types
    • More JavaScript Data Types
  • JavaScript Expressions and Statements
  • if/else, switch and ternary operator
    • If/Else statement
  • Switch Statement
  • Ternary Operator
  • JavaScript Loops
    • Loops in JavaScript
      • Trouble With Loops
  • Objects
    • JavaScript Objects
      • Prototypal Inheritance Visualized
      • JavaScript Number Object
      • JavaScript String Object
  • Functions
    • JavaScript Function Part One
    • JavaScript Function Part Two
    • Immediately Invoked Function Expressions ~ IIFE
    • JS => Arrow Functions
    • JavaScript Callback
    • Hoisting in JavaScript
      • Hoisting Visualized
    • Recursion Functions
    • Curry and Function Composition
  • JavaScript Features
    • JSpread Operator
    • JavaScript Built-in Functions & Objects
  • Data Structures&Algorithms
    • JavaScript’s Data Types
    • Data Structures in JavaScript
      • Introduction to Big O Notation
      • Big O Notation in Javascript
      • Linked Lists
        • Linked Lists — 2
      • Hash Tables
      • Stack & Queue
  • TLDR
    • Single quotes (‘ ’) and double quotes (“ ”) in JavaScript
  • ES6
    • Generators and Iterators
    • Javascript Classes
    • JavaScript closures
    • JavaScript Promises & Async/Await
      • Event Loop Visualized
  • C#
    • What does C#? (C Sharp)
    • C# vs JavaScript
    • What Is The Difference Between C#, .NET, ASP.NET, Microsoft.NET, and Visual Studio?
    • What is the .NET Framework?
    • Methods and Properties of Console Class in C#
    • Datatypes in C#
    • C# Code Comments
    • The if statement
    • The switch statement
    • Loops
    • Comparison operators
    • Addition assignment operators
    • The String Interpolation Operator
    • Arrays
    • Lists
    • Dictionaries
Powered by GitBook
On this page
  • ‘Single quotes “escape” single quotes’
  • “Double quotes ‘escape’ double quotes“
  • "Empty" === 'Empty'
  • Are `backticks` a better solution?
  • Don’t forget about JSON
  • What is wrong with using all 3?
  • Use ESLint for consistency
  • Use prettier and stop worrying about it

Was this helpful?

  1. TLDR

Single quotes (‘ ’) and double quotes (“ ”) in JavaScript

PreviousStack & QueueNextGenerators and Iterators

Last updated 5 years ago

Was this helpful?

Both single quotes ('') double quotes ("") are used frequently in JavaScript to create a .

A literal is , as opposed to a reference, which would be indicated by the variable name.

There is only one difference between the use of single quotes ('') and double quotes ("") in JavaScript, and it comes down to which quote character you have to escape using the backslash (\) character: \' or \".

‘Single quotes “escape” single quotes’

When using single quotes ('') to create a string literal, the single quote character needs to be escaped using a backslash (\').

“Double quotes ‘escape’ double quotes“

When using double quotes "" to create a string literal, the double quote character needs to be escaped using a backslash: \".

"Empty" === 'Empty'

Either two double "" or single '' quote marks next to each other can represent an containing no characters at all.

Are `backticks` a better solution?

An ES6 feature called template literals, backtick literals, or backticks uses backticks `` instead of a single '' or double quote "".

“Template literals are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them.” —

  1. Easier string concatenation (“variable interpolation”) "string "+variable becomes `string ${variable}`

  2. No need to escape (\) single or double quotes "\"Hello World!\"" becomes `"Hello World"`

  3. Multi-line code without new line character (\n) "Hello\nWorld!" becomes `Hello World`

Don’t forget about JSON

If I happen to be copying back-and-forth from JavaScript to JSON files, using just double quotes helps me stay consistent.

This is pretty rare — I just try to remember to not use single quotes in JSON.

When handling JSON files from within JavaScript, the stringify() and parse() functions know about the double quotes already:

What is wrong with using all 3?

Yes, there would be nothing wrong with using “ ” by default, ‘ ’ for strings including double-quotes, and ` ` for including variables or multi-lines.

It comes down to personal preference, though many people lobby for picking one and using it consistently when creating JavaScript strings.

Use ESLint for consistency

  • The quotes rule can also enforce one type of quote except when the string contains a quote character that would have to be escaped otherwise.

  • And finally, ESLint can require single or double quotes but still allow strings to use backtick literals.

Use prettier and stop worrying about it

JavaScript Object Notation ), the lightweight data storage format, only allows double quotes.

For example, prefers single quotes (‘ ’), avoids double quotes (“ ”), and uses backtick literals (` `) sparingly:

Use single quotes '' for strings. —

If consistent quote style in JavaScript is important to you, like it is to the engineers at Airbnb, then it is easy to fix with :

The ESLint rule can require the use of double quotes (default), single quotes, or backticks whenever possible.

An easier (or supporting) solution to using ESLint to keep quote styles consistent is to use for automatic formatting.

With prettier on, the default is double quotes, but requiring single quotes is just a toggle away — at least when using prettier at .

There is also a .

string literal
another word for a value
empty string
MDN Docs
(JSON
Airbnb’s style guide
6.1
Airbnb
ESLint
quotes
prettier
CodeSandbox.io
VSCode extension available for prettier