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.
You can enable the strict mode by declaring this in the top of your script/function. 'use strict'; When a JavaScript engine sees this directive, it will start to interpret the code in a special mode.
ES6 modules and classes are strict by default.
Using Strict mode for a function: Likewise, to invoke strict mode for a function, put the exact statement “use strict”; (or 'use strict';) in the function's body before any other statements. Examples of using Strict mode: Example: In normal JavaScript, mistyping a variable name creates a new global variable.
We can also apply this to functions. To do this, we add the statement "use strict" or 'use strict' inside the functions on the top of the body, before any other statements. It's applied to everything inside, including functions that are nested in the function that uses strict mode.
For you, without using a browser that supports strict mode:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With