JavaScript:能否使用单引号(“ use strict”)启用ECMAScript 5的“严格模式”(“ use strict”)? [英] JavaScript: Can ECMAScript 5's Strict Mode ("use strict") be enabled using single quotes ('use strict')?

查看:182
本文介绍了JavaScript:能否使用单引号(“ use strict”)启用ECMAScript 5的“严格模式”(“ 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 whose StringLiteral 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆