GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Main Page
  • Help
  • Browse
  • Cookbook
  • Wikijunior
  • Featured books
  • Recent changes
  • Special pages
  • Random book
  • Using Wikibooks
  • Reading room forum
  • Community portal
  • Help out!
  • Policies and guidelines

This view

  • Original page
  • New address

GeezerVison is showing en.wikibooks.org — JavaScript/Strict mode - Wikibooks, open books for an open world

< JavaScript
(Redirected from JavaScript/Strict Mode)


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:

  • New variables need to be declared with "var"; "var" is no longer optional.
  • Attempts to write to non-writable variables throw an error rather than silently doing nothing.
  • Attempts to delete undeletable properties throw an error rather than silently doing nothing.
  • Octal numerals are disallowed.
  • Etc.

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

External links

  • Strict mode, developer.mozilla.org
  • JavaScript Use Strict, w3schools.com
  • Strict Mode (JavaScript), msdn.microsoft.com
Retrieved from "https://en.wikibooks.org/w/index.php?title=JavaScript/Strict_mode&oldid=4666632"
Category:
  • Book:JavaScript
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.