JavaScript/Strict mode

< JavaScript

The strict mode

Strict mode can be enabled by placing '"use strict";' at the beginning of a script, before other statements:

// Dummy comment
"use strict";
var myvar = 4;

It can also be enabled for a single function only:

function myfun(){
  "use strict";
  var myvar = 6;
}

Strict mode ensures the following:

Strict mode is available since JavaScript 1.8.5, i.e. ECMAScript version 5.

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.