JavaScript:能否使用单引号(“ use strict”)启用ECMAScript 5的“严格模式”(“ use strict”)? [英] JavaScript: Can ECMAScript 5's Strict Mode ("use strict") be enabled using single quotes ('use strict')?
问题描述
JavaScript不在乎您的字符串是用双引号双
还是用单引号'single'
。
JavaScript doesn't care if your Strings are double-quoted "double"
or single-quoted 'single'
.
每个ECMAScript 5严格模式的示例都通过在双引号中使用 use strict
来启用它。我可以做以下(单引号)吗?
Every example of ECMAScript 5's strict mode has it enabled by "use strict"
in double-quotes. Can I do the following (single-quotes):
alert(function(){
'use strict';
return !this;
}());
如果启用了严格模式,则返回 true ,而如果不是,则返回false 。
This will return true if Strict mode is enabled, and false if it is not.
推荐答案
使用严格指令是指令序言中
ExpressionStatement
> StringLiteral 是确切的字符序列use strict
或'use strict'
。使用严格指令可能不包含EscapeSequence或LineContinuation。
A Use Strict Directive is an
ExpressionStatement
in a Directive Prologue whoseStringLiteral
is either the exact character sequences"use strict"
or'use strict'
. A Use Strict Directive may not contain an EscapeSequence or LineContinuation.
这篇关于JavaScript:能否使用单引号(“ use strict”)启用ECMAScript 5的“严格模式”(“ use strict”)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!