console.log("double");
vs. console.log(\'single\');
I see more and more JavaScript libraries out there using single quotes when ha
Examining the pros and cons
In favor of single quotes
elem.innerHTML = 'Hello';
elem.innerHTML = "Hello";
Furthermore, inline HTML is normally an anti-pattern. Prefer templates.
myJson = '{ "hello world": true }';
Again, you shouldn’t have to construct JSON this way. JSON.stringify() is often enough. If not, use templates.
In favor of double quotes
In favor of both
There is no difference between the two in JavaScript. Therefore, you can use whatever is convenient at the moment. For example, the following string literals all produce the same string:
"He said: \"Let's go!\""
'He said: "Let\'s go!"'
"He said: \"Let\'s go!\""
'He said: \"Let\'s go!\"'
Single quotes for internal strings and double for external. That allows you to distinguish internal constants from strings that are to be displayed to the user (or written to disk etc.). Obviously, you should avoid putting the latter in your code, but that can’t always be done.