This is the concept usually asked in the JavaScript interviews, but mostly developers does not give the answers, As its uncommon to use in the programming.

Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a “strict” operating context. This strict context prevents certain actions from being taken and throws more exceptions.

Strict mode helps out in a couple ways:

1. It catches some common coding bloopers, throwing exceptions.

2. It prevents, or throws errors, when relatively “unsafe” actions are taken (such as gaining access to the global object).

3. It disables features that are confusing or poorly thought out.

you can apply “strict mode” to the whole file Or you can use it only for a specific function. like

// Non-strict code...

(function(){
  "use strict";

  // Define your library strictly...
})();

// Non-strict code...

List of features

  1. Disallows global variables. (Catches missing var declarations and typos in variable names)
  2. Silent failing assignments will throw error in strict mode (assigning NaN = 5;)
  3. Attempts to delete undeletable properties will throw (delete Object.prototype)
  4. Requires all property names in an object literal to be unique (var x = {x1: "1", x1: "2"})
  5. Function parameter names must be unique (function sum (x, x) {...})
  6. Forbids octal syntax (var x = 023; some devs assume wrongly that a preceding zero does nothing to change the number.)
  7. Forbids the with keyword
  8. eval in strict mode does not introduce new variables
  9. Forbids deleting plain names (delete x;)
  10. Forbids binding or assignment of the names eval and arguments in any form
  11. Strict mode does not alias properties of the arguments object with the formal parameters. (i.e. in function sum (a,b) { return arguments[0] + b;} This works because arguments[0] is bound to a and so on. )
  12. arguments.callee is not supported

Also see: React Interview Questions and Answers

Node.js Interview Question for Beginners

Similar Posts