Akiko: Handsome people are concerned

Making: making

Hobby: Americano More Ice!

Project source: project Github source code! Star to walk again

directory

  • directory
    • define
    • Why use Strict mode
    • Use strict Specifies the scope of the mode

define

  • The statement formats
"use strict"; (official website) <! - or - >'use strict'
Copy the code
  • define

The “Use Strict” feature was added in ES5(ECMAScript 5) to indicate that code enforces strict patterns.

  • Declare scope

Generally declared at the beginning of the script, with global scope (all code in the script is executed in strict mode)

PS: Special case, if declared inside a function, it has only local scope (only code inside a function is in strict mode)

x = 3.14;       // This will not cause an error.
myFunction();

function myFunction() {
  "use strict";
  y = 3.14;   // This will cause an error
}
Copy the code

Why use Strict mode

  • It’s easier to write in this modesecuritytheJavaScript
  • Unacceptable in this mode -> previously acceptableWrong grammar

For example, in normal JavaScript, typing a variable name incorrectly creates a new global variable. In strict mode, this raises an error, making it impossible to accidentally create a global variable.

As another example, in strict mode, any assignment to an unwritable property, getter-only property, non-existent property, non-existent variable, or non-existent object raises an error.

Use strict Specifies the scope of the mode

  • Variables: var, delete, let variable keywords
  • Object: read-only property, object property repeated declaration
  • Function: arguments with the same name, arguments object declaration
  • Others: this, eval, keywords…

Conclusion: if encounter what question or suggestion, can leave a message comment directly! The author will reply immediately

If you feel small white this article is good or helpful to you, look forward to your one key three even 💫! ❤ ️ ni ~