为什么 JSLint 要我使用双引号而不是单引号?预期 ''' 而不是看到 '''

Why is JSLint wanting me to use double quotes instead of single quotes? Expected '"' and instead saw '''

我最近开始看到 JSLint 发出以下警告:

JSLint: Expected '"' and instead saw '''.

换句话说,就是要我用双引号代替单引号。为什么 JSLint 会就此警告我?单引号和双引号在 JavaScript 中不是或多或少可以互换的吗?

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.

这确实发生了:option.single 已添加到 JSLint 的 2016-06-09 version 中,因此您现在可以告诉 JSLint 选择性地忽略单引号。

Crockford 在 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.

这是一个非常自以为是的工具发出的垃圾邮件警告,没有充分的理由。

旧的 lint 工具(JSLint 和 JSHint)已完全被 ESLint, which supports more rules and allows you configure the options you're actually interested in. Specifically, the quotes rule 取代,允许您 select 单引号、双引号或完全忽略引号。