use strict Directive

By: Dusty Arlia
Published on Monday, May 6, 2013, 01:00 PM
Last Updated on Friday, July 17, 2015 at 4:15 PM
Total Updates: 5

The "use strict" directive is used to signal to the JavaScript interpreter that the code to follow is strict code. Place this directive at the top of your script to indicate that the script is strict code. Or, if you just need a function with strict code, place this directive at the beginning of your function's body. If your function is defined from inside strict code, than adding the directive a second time is unnecessary. The strict code is then executed in strict mode.

The "use strict" directive is a special string literal expression statement that was introduced in ECMAScript 5. If a JavaScript interpreter does not implement ECMAScript 5, it will see an expression statement with no side effects and do nothing. The string use strict is placed either between single quotes ('') or double quotes (""). There are no keywords in this statement. Future versions of the ECMAScript standard are expected to introduce use as a new keyword. If this happens, there will no longer be a need for quotation marks.

The "use strict" directive can appear either at the beginning of your script or at the beginning of a function's body. Any string literal expression statements that come after the first regular statement in a script or function will be interpreted as an ordinary expression statement and will have no side effects. These statements will not be interpreted as directives.

Comments:

Ad: