Currently there are three ways of declaring strings in ES6 that I am aware of.
String Template Literals
`Hello World!`
Pros: Easy to extend with dynamic content (${}
). Looks most appealing with dynamic content.
Cons: Looks very strange and pointless when used without ${}
. Awkard to use since it prints only after another character has been typed and also can add unwanted accents when typed carelessly (o
-> รณ
)
I am using a german keyboard, so I am not 100% sure if those problems apply to other langauge specific keyboards too.
Single Quotes
'Hello World!'
Pros: Very minimal and clean
Cons: Used for single characters ('a'
, 'b'
, 'c'
) in other langagues (e.g. C#)
Double Quotes
"Hello World!"
Pros: Very familiar and used in other langauges the same way (e.g. C#)
Cons: Visually, takes up most space and looks less "clean" (this might be just my opinion).
Thoughts
I want to keep my code clean and consistent. Switching between those versions feels awkard and unclean to me.
What are your opinions? Which version do you prefer and why? Did I miss any pros or cons?
I also wonder if there are any downsides considering performance when using those different methods, especially looking at string template literals.