M
As others have said, the strict mode is a more rigorous way of interpreting language, which prohibits certain practices that have always been permitted, but are not recommended (such as creating implicit global variables, already mentioned in other responses). As simply unconditionally prohibiting this type of practice would break legacy codes, it was decided to create the directive "use strict"; to activate strict mode.There are two ways to use "use strict":At the top of the file, the directive applies strict mode to the entire file.As the first code line of a function, the directive applies strict mode only within the function (including other functions eventually declared within it).The great benefit of using strict mode is to reduce the chance of existing in the code bugs difficult to locate (such as a name conflict when creating an implicit global, or the existence of two equal keys in literal object).Prepared a free and adapted translation of https://www.ecma-international.org/ecma-262/9.0/index.html#sec-strict-mode-of-ecmascript , which summarizes the existing restrictions in strict mode:The identifiers implements, interface, let, package, private, protected, public, static, and yield are reserved words when used in strict mode.Numerical literatures are never considered octal, even when they start with zero. The same goes for octals escaped in strings, as '\012' (that modern browsers do not support more, even outside strict mode)Trying to assign a value to a variable that does not exist in the current scope does not create another property in the global object (i.e. it does not create a global variable anymore). Instead, it throws an exception of the ReferenceError type. In addition, it is not possible to assign to properties that have the attribute {[[Writable]]:false}, nor to a accessor without setter defined ({[Set]]:undefined}), nor for properties of objects whose internal property [[Extensible]]] is false. In all these cases a TypeError will be released.It is not possible to reset eval, nor use it with ++ or --. If you try to access arguments.caller or arguments.callee in a function, a TypeError will be released.Named arguments of functions do not share values dynamically with the equivalent properties indexed numerically. For example, in function foo(bar) { arguments[0] = 10; }, bar maintains the value passed in the call and does not assume the value 10.The same is true in the reverse case: function foo(bar) { bar = 10; }, arguments[0] maintains the value passed in the call and does not assume the value 10.If there is more than one property with the same name on a literal object, a SyntaxError is released."eval" and "arguments" identifiers cannot be used as function parameters names that define getters or setters in literal objects (even if the external code is not in strict mode, but the body of the getter/setter is).O eval in strict mode cannot instace variables or functions in the scope of who calls eval. The code passed to eval will create a new scope, where these variables will be instantiated.In strict mode, there is no coercion this for object. In cases where this for null or undefined, it will not be converted to the global object. For example: function f(){ console.log(this) }; f();, this It is undefined in strict mode, and not the global object (in browsers, window). Moreover, if a primitive value is passed as this, he will not be converted to wrapper equivalent.The operator delete launches a SyntaxError when used in non-deletable items such as variables, functions and arguments. For example: delete variavel, delete funcao and function(foo) { delete foo; }.The operator delete launches a TypeError if the property to be deleted has the attribute { [[Configurable]]:false }.If you try to declare a variable named "eval" or "arguments", a SyntaxError will be released.The use of with launches a SyntaxError.In a clause catch it is not possible to use "eval" or "arguments" as the name of the exception; this is a SyntaxError."eval" and "arguments" identifiers cannot be used as function parameters names; this is a SyntaxError.Functions cannot have multiple parameters with the same name; this is a SyntaxError.It is prohibited for implementations to extend the meaning of the "caller" and "arguments" properties of instances of functions beyond the specification.It is a SyntaxError try to use "eval" or "arguments" as a function name or parameter, as well as try to force it through the builder Function.