Rudiger
Rudiger

Reputation: 411

JavaScript: Can ECMAScript 5's Strict Mode ("use strict") be enabled using single quotes ('use strict')?

JavaScript doesn't care if your Strings are double-quoted "double" or single-quoted 'single'.

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;
}());

This will return true if Strict mode is enabled, and false if it is not.

Upvotes: 40

Views: 5580

Answers (3)

Felix Kling
Felix Kling

Reputation: 816462

For you, without using a browser that supports strict mode:

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.

Upvotes: 61

Elian Ebbing
Elian Ebbing

Reputation: 19037

According to the mozilla documentation you can use both "use strict"; and 'use strict';.

Upvotes: 5

user113716
user113716

Reputation: 322502

http://ecma262-5.com/ELS5_HTML.htm#Section_14.1

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.

Upvotes: 28

Related Questions