Strict Strict mode

Source: Internet
Author: User

Strict mode allows you to find errors earlier, because those that are prone to errors in the program are identified   turned on strict mode: the JavaScript engine that "use strict" does not support ignores it and treats it as an unassigned string. If you use strict mode for global use in a script, other scripts on the same page will be strict. You can also declare the use of strict mode in a function.   In peacetime, there is no declaration that the directly used variable is treated as a global variable number = 1; In strict mode, a reference error (REFERENCEERROR) is thrown and the variable cannot be delete, and the delete number will silently fail. Quote type error   Strict mode, variable and function names cannot be used in strict mode Implements,interface,let,package,private,protected,public,static,yield This is reserved for later use   has a greater limit on the operation of the object, for many of the usual quiet failure operations will be error: Assigning a value to a Read-only property throws a typeerror.using delete On a nonconfigurable property throws a typeerror.attempting to add a property to a Nonextensible object throws a TypeError .  Also, cannot declare duplicate property: var person = {   name: "Nicholas",   name: "Greg"};  function The name of the row parameter must be unique, in the ordinary will not error, Directly using the following: function sum (num, num) {//do something}   in the usual function to change the parameters passed in, arguments will follow the change, but strict mode will not. In strict mode, the two are separated independently. function Showvalue (value) {value = "foo"; alert (value);//"foo" alert (Arguments[0]);//non-strict mode: "foo"//strict Mode: "Hi"}showvalue ("HI");  the following two in strict modeCannot be used: Arguments.callee can normally access the function itself Arguments.caller   can access the caller  function declaration that calls this function must be at the top level of a script or Functionif (true) {    function dosomething () {//...} } This will be an error.   for the Eval function, the biggest limitation is that the variable or function is not created within the execution context that contains it: function DoSomething () {eval ("var x=10"), alert (x);//Throw Referenceerror}   is not in the execution context of eval or can create variables, but will receive a limit, these variables are saved to a special scope, the code will be destroyed after execution: "Use strict"; var result = eval ("var x=10, y=11; X+y "); alert (result); 21 when the alert is executed here, X, Y has been destroyed   explicitly cannot define the operation eval and arguments:-?  declaration using var-?  assignment to another value-?  attempts to change the contained value, such as using ++-?  used as function names-?  used as named function arguments-?  used as exception name in Try-catch statement  restrictions on this, the following example in the usual this to point to the global variable, output red, strict mode error will occur, Because this will only point to nullvar color = "Red", function Displaycolor () {        alert (this.color);} Displaycolor.call (NULL);  Strict mode also removes some common errors, such as with, that do not allow changes to the octal  parseint function: var value = parSeint ("010") non-strict mode output 8, strict mode output 10  adding "use strict" before code that requires strict mode simply a function can also  function dosomething () {' Use strict ';  //function body}  This mode will change many modes of operation

Strict Strict mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.