Monday, January 26, 2015

I was discussing with some friends about single quotes and double quotes in JS. While the JSON specification...

I was discussing with some friends about single quotes and double quotes in JS. While the JSON specification tells us to double quote keys and values, linting tools like Google's closure compiler are recommending single quotes.



Lookin' for an answer, greppin' the Internets, I only found answers like "it's programmer's choice". What's your opinion about this?



For JSON, it is easy. Always use double quotes.



For JavaScript, I recommend using double quotes for strings that make sense outside of the program: error messages, urls, html fragments, etc.



Use single quotes for strings that only make sense to the program: symbols, property names, character constants, etc.



The advice "Programmer's choice" is usually very bad advice. Always look deeper.




No comments:

Post a Comment