Skip to content

Instantly share code, notes, and snippets.

@srkmrs
Last active December 22, 2015 03:19
Show Gist options
  • Select an option

  • Save srkmrs/6409678 to your computer and use it in GitHub Desktop.

Select an option

Save srkmrs/6409678 to your computer and use it in GitHub Desktop.
Use Strict
By marking the top of the script block or function with the "use strict” directive,
the compiler will provide early warnings and errors for common coding mistakes,
and restrict the usage of some dark corners of the JavaScript language.
Let you see how the following sample code interact with Strict Mode.
Code
"use strict";
a = 100;
b = 200;
document.write(a + b);
Results
Error was detected; no results were produced.
Errors
Uncaught ReferenceError: a is not defined
Expected Code
"use strict";
var a = 100;
var b = 200;
document.write(a + b);
Results
300
Errors
No errors.
(Note that Strict Mode is still under development in many browsers.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment