javascript – 为什么JSLint希望我使用双引号而不是单引号?预期”’而是看到”’

我最近开始看到JSLint提供以下警告:

JSLint: Expected ‘”‘ and instead saw ”’.

换句话说,它希望我使用双引号而不是单引号.为什么JSLint警告我这个?不是单引号和双引号在JavaScript中可以互换,只受程序员的偏好?

解决方法

JSLint的 2016-02-07 version改为比单引号更喜欢双引号. Douglas Crockford,JSLint的开发人员和JavaScript和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.

这确实发生了:在JSLint的2016-06-09 version添加了option.single,因此现在可以告诉JSLint可以忽略单引号.

克罗克福德更简洁地重申了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.

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...