Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the limitations of JavaScript strict mode

Shulou Source: shulou.com Published: 2022-06-01 10:30:56 09月25日 Update

Most people do not understand the knowledge points of this article "what are the restrictions on the strict mode of JavaScript?", so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article, "what are the restrictions of JavaScript strict mode?"

The limitation of strict mode

Undeclared variables are not allowed:

"use strict"

Function x (p1, p1) {}; / / error report

Object is also a variable.

"use strict"

Var x = 010; / / error report

Deletion of variables or objects is not allowed.

"use strict"

Var x = 3.14

Delete x; / / error report

Deletion of functions is not allowed.

"use strict"

Function x (p1, p2) {}

Delete x; / / error report

Duplicate names of variables are not allowed:

"use strict"

Function x (p1, p1) {}; / / error report

Octal is not allowed:

"use strict"

Var x = 010; / / error report

Escape characters are not allowed:

"use strict"

Var x =\ 010; / / error report

Assigning values to read-only properties is not allowed:

"use strict"

Var obj = {}

Object.defineProperty (obj, "x", {value:0, writable:false})

Obj.x = 3.14; / / error report

It is not allowed to assign a value to an attribute read using the getter method

"use strict"

Var obj = {get x () {return 0}}

Obj.x = 3.14; / / error report

Deletion of an attribute that is not allowed to be deleted is not allowed:

"use strict"

Delete Object.prototype; / / error report

Variable names cannot use the "eval" string:

"use strict"

Var eval = 3.14; / / error report

Variable names cannot use the "arguments" string:

"use strict"

Var arguments = 3.14; / / error report

The following statements are not allowed:

"use strict"

With (Math) {x = cos (2)}; / / error report

For some security reasons, variables created in scope eval () cannot be called:

"use strict"

Eval ("var x = 2")

Alert (x); / / error report

The above is the content of this article on "what are the restrictions on the strict mode of JavaScript". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Tags: Variables contents patterns restrictions characters attributes strings objects articles knowledge articles security values functions octal functions reasons most of which are methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS NVidia Shulou Technology Microsoft