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.

Rudiger
  • 411
  • 4
  • 5

3 Answers3

62

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.

Michael Thompson
  • 541
  • 4
  • 21
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
  • 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. – Eric May 06 '12 at 18:49
  • Okay, but how about JS engine support? I don't think there are any known quirks at the moment, but I'm not sure. – user123444555621 Jul 29 '13 at 14:58
  • @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. – Felix Kling Aug 21 '13 at 16:39
  • 1
    @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. – user123444555621 Aug 21 '13 at 18:38
  • @Pumbaa80: Ah. I don't know, I don't think so. – Felix Kling Aug 21 '13 at 19:32
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.

user113716
  • 318,772
  • 63
  • 451
  • 440
5

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

Elian Ebbing
  • 18,779
  • 5
  • 48
  • 56