"use strict" strict mode

    Strict mode was introduced in ES5, which defines a new parsing and execution model for JavaScript. In strict mode, some undefined behavior in ES3 will be handled, and some unsafe operations will throw errors.
1. Function

    (1) Eliminate some irregularities and imprecisions in JS, and reduce some weird behaviors;

    (2) Throwing errors for some unsafe code operations to improve security;

    (3) Improve the efficiency of the compiler and improve the running speed

2. Restrictions

    (1) Variables must be declared before use, and a global variable cannot be deleted;

    (2) The parameters of the function cannot have the same name (only the second parameter of the same name can be accessed in non-strict mode), and the object properties cannot have the same name (the latter will automatically overwrite the former in non-strict mode)

        Formal parameters are not changed in strict mode

function show(value){
		'use strict'
		value='abc';
		alert(value);
		alert(arguments[0]);
	}
	show('hi');//abc,hi

    (3) Prohibit the use of octal

    (4) The with statement cannot be used

    (5) Cannot delete undeletable attributes

    (6) The arguments.callee method cannot be used

    (7) Added reserved words: protected static interface, etc.

    (8) The eval() scope is established

    (9) Display error

3. Disadvantages

    (1) Some statements that can run in normal mode may not run in strict mode

    (2) Not flexible enough

4. Use
    (1) For the entire script file, declare "use strict" at the very beginning of a script

      (2) For a function, declare "use strict" in the first line of a function body

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324706593&siteId=291194637