40

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.

2
  • 1
    @Myles Gray - I don't have a browser that supports Strict mode at work :( Commented Mar 7, 2011 at 0:00
  • @Felix Kling - None of the major browsers support Strict mode :( See kangax.github.com/es5-compat-table Commented Mar 7, 2011 at 0:06

3 Answers 3

61

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.

Sign up to request clarification or add additional context in comments.

5 Comments

If you are using gzip to compress the content then I would recommend using double quotes or single quotes depending on which one shows up most in the document.
Okay, but how about JS engine support? I don't think there are any known quirks at the moment, but I'm not sure.
@Pumbaa80: You mean if there is a problem if strict mode is not supported? I highly doubt it. The syntax was chosen to make it backwards compatible. An engine that does not support strict mode simply sees an expression statement with a lone string literal.
@FelixKling That's not what I meant. I was wondering whether there might be an engine that triggers strict mode when seeing "use strict", but not when seeing 'use strict', even though the two are supposed to be equivalent.
@Pumbaa80: Ah. I don't know, I don't think so.
28

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.

Comments

5

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.