DEV Community

Discussion on: 'Single' vs "Double" quotes for strings in javascript

Collapse
 
taufik_nurrohman profile image
Taufik Nurrohman • Edited

I think this is just a personal preference. No?

Everyone has their own style. As long as they are consistent, then that would be fine. Would like to see some style guide about it that has been used by people around the world.

To me, I will use single-quote string by default. If it has a potential to have only single-quote character in it, then I would use double-quote so that I can remove the escape character.

I use double-quote to represent empty string because it feels more assertive. As to type it requires me to press the Shift key.

Example:

let element = '<a href="#">aaa</a>',
    hash = window.location.hash;
if ("" === hash || 0 === hash.indexOf("'")) {
    window.location.hash = '#aaa';
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
drarig29 profile image
Corentin Girard • Edited

Second time I see someone using Yoda comparison πŸ˜ƒ
eslint.org/docs/2.0.0/rules/yoda

I don't use it personally, it's just funny to me.