When should you use single quotes or double quotes for strings?

  1. When to use single quotes (’ ') and when double (" ")?
  2. Does numbers include negative?
  1. This is a personal preference, I prefer the high visibility of double quotes myself. Also this is one thing that ES6 Template Literals help solve (its a better string!)

  2. Yes


Why are single quote strings used to frequently here? While in the case of JavaScript, string literals do not exist in their proper context, it severely damages readability of the script when you get into value substitution and use of escape characters while still encasing them with single quotes, which in a majority of languages, albeit mainly compiled ones, represents a literal string. A string with no variables, no escape characters, and an innate form of simple input validation.

i dont know? but can someone please tell me

I personally think strings should be with double quotation marks even just for avoiding this simple error:
console.log('I don't like double quotation');

1 Like

As per Airbnb Best Practices:-
We should use single quote strings as it is a Good Practice. You can still use double quotes but not a Good Practice.

But is there any good reason why?

If you want to print something covered with double quote you should use single quote to the console.

console.log ( ' I love "codecademy" ' )

Or if you want to print something covered with single quote you should use double quote to the console.

console.log ( " I Love 'codecademy' ")

Many other reasons may be there. I have found this at the beginning level of my learning js.

1 Like