Features of JavaScript Strict Mode

By: Dusty Arlia
Published on Wednesday, May 8, 2013, 06:58 AM
Last Updated on Wednesday, July 08, 2015 at 10:32 PM
Total Updates: 2

  • with statements are not allowed in strict mode.
  • All variables must be declared in strict mode. A ReferenceError is thrown if you assign a value to an undeclared variable, function, parameter, or property.
  • Functions invoked as functions have a this value of undefined.
  • When a function is invoked with call() or apply(), the this value is equal to the first argument of call() or apply().
  • Assignments to nonwritable properties and attempts to create new properties on nonextensible objects throws a TypeError.
  • Code passed to eval() cannot declare variables or define functions in the caller's scope. Instead, variables and function definitions get created in a new scope created for eval(). This scope is discarded when the eval() returns.
  • The arguments object in a function holds the values passed to the function, but the values stored in the arguments object are not dynamically linked to the parameter values.

    For example:

    document.write(x);                                       //writes value of first parameter
    arguments[0] = "A string argument passed to a function"  //changes value of the first parameter
    document.write(x);                                       //still writes the original value of x
    
  • If the delete operator is followed by an unqualified identifier like a variable, function, or function parameter name, then a SyntaxError is thrown.
  • If you try to delete a nonconfigurable property, the JavaScript interpreter will throw a TypeError.
  • A syntax error is thrown if an object literal has two or more properties with the same name.
  • A syntax error is thrown if a function declaration has two or more parameters with the same name.
  • Octal literals are not allowed.
  • The eval and arguments identifiers should be treated as keywords. You are not allowed to change their value. Also, you can't declare them as variables, functions, function parameters, or as a parameter to a catch clause.
  • Access to the call stack is restricted. TypeError's are thrown using arguments.caller and arguments.callee from inside a strict mode function. Strict mode functions also have caller and arguments properties that throw TypeError's when read.

Comments:

Ad: