I recently started seeing JSLint giving the following warning:
JSLint: Expected '"' and instead saw '''.
In other words, it's wanting me to use double quotes instead of single quotes. Why is JSLint warning me about that? Aren't single quotes and double quotes more or less interchangeable in JavaScript, subject only to the programmer's preference?
The 2016-02-07 version of JSLint changed to prefer double quotes over single quotes. Douglas Crockford, developer of JSLint and influential developer for JavaScript and JSON, provided this rationale:
When I first met JavaScript, it [sic] was surprised that it had the two kinds of quotes, and I tried to make sense of it, using single for internal text, and double for external.
But eventually I realized that distinction isn't worth the clutter and confusion that comes from having two when only one is needed. I decided to go with double because that is what JSON uses, and it avoids errors caused by the overloading of apostrophe. I have been bitten by that.
In general, I am looking for ways to make the language smaller and better. Quotes fall in the same class as null & undefined. We really don't need both.
I tried it out on some of my own code, and I think it is an improvement. Eventually, I may add option.single to JSLint.
This did happen: option.single
was added in the 2016-06-09 version of JSLint, so you can now tell JSLint to optionally ignore single quotes.
Crockford more succinctly reiterated his rationale for double quotes over single quotes in a later discussion:
I found that people had some difficulty managing the two types of quotes. Since the second set is completely unnecessary, and since the second set [single quotes] can introduce problems and confusions, I now recommend using double quotes only.
This is a spam warning from a very opinionated tool, there's no good reason for it.
The old lint tools (JSLint and JSHint) have been wholly superseded by ESLint, which supports more rules and allows you configure the options you're actually interested in. Specifically, the quotes
rule allows you to select single, double, or ignore quoting entirely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With