Strict Mode

Opt-in using the pragma "use strict"

Applied to the top of a function makes the whole function run in strict mode. Applied to the top of a script makes the whole script run in strict mode. es6 modules run implicitly in strict mode.

Sloppy ModeStrict Mode
this default bindingglobal Objectundefined
accidental global variable car = 42;applies property to global objectthrows Reference error
delete read-only propfails silentlythrows TypeError
add prop to a non-extendible objectfails silentlythrows TypeError
change property descriptor if configurable is falsefails silentlythrows TypeError
withworks normallythrows Error
octal notation: let a = 05;worksforbidden throws SyntaxError only let a = 0o5; works
assign properties to primitives (2).a = 3; window.undefined = true; "a".a = "a";fails silentlythrows TypeError
eval and arguments used as variable/property namesworksthrows TypeError
delete plainNames delete that;worksthrows SyntaxError
addings variables to scope using eval eval("var r = 3;")adds variable to scopedoesnt not add a variable

References