For the More Curious: Strict Mode
What is strict mode, and why does it exist? It was created as a cleaner mode of JavaScript, catching certain kinds of coding mistakes (like typos in variable names), steering developers away from some error-prone parts of the language, and disabling some language features that are just plain bad.
Strict mode provides a number of benefits. It:
-
enforces the use of the
var
keyword -
does not require
with
statements -
places restrictions on the way the
eval
function can be used -
treats duplicate names in a function’s parameters as a syntax error
All this just for adding the
'use strict'
directive to the top of a function.
As a bonus, the 'use strict'
directive is ignored by older browsers ...
Get Front-End Web Development: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.