Problem at line 1 character 1: Missing "use strict" statement.
Doing some searching, I realized that some people add
So what is
"use strict";all about, what does it imply, and is it still relevant?
Do any of the current browsers respond to the
"use strict";string or is it for future use?
Update for ES6 modules
Inside native ECMAScript modules (with
exportstatements) and ES6 classes, strict mode is always enabled and cannot be disabled.
To quote some interesting parts:
Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a "strict" operating context. This strict context prevents certain actions from being taken and throws more exceptions.
Strict mode helps out in a couple ways: It catches some common coding bloopers, throwing exceptions. It prevents, or throws errors, when relatively "unsafe" actions are taken (such as gaining access to the global object). It disables features that are confusing or poorly thought out.
Also note you can apply “strict mode” to the whole file… Or you can use it only for a specific function (still quoting from John Resig’s article):
So, I suppose it’s a bit like the
"use strict"you can use in Perl (hence the name?): it helps you make fewer errors, by detecting more things that could lead to breakages.
Strict mode is now supported by all major browsers.
If you have better answer, please add a comment about this, thank you!