top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is Strict Mode in JavaScript ?

0 votes
421 views

Give the example for strict mode "use strict"

posted Aug 4, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

Strict mode makes several changes to normal JavaScript semantics.

  • strict mode eliminates some JavaScript silent errors by changing them to throw errors.

  • strict mode fixes mistakes that make it difficult for JavaScript engines to perform optimizations.

  • strict mode prohibits some syntax likely to be defined in future versions of ECMAScript.

Strict mode is supported in:
Internet Explorer from version 10, Firefox from version 4,Chrome from version 13, Safari from version 5.1, Opera from version 12.

Example of Strict mode:

"use strict";
eval = 17;
arguments++;
++eval;
var obj = { set p(arguments) { } };
var eval;
try { } catch (arguments) { }
function x(eval) { }
function arguments() { }
var y = function eval() { };
var f = new Function("arguments", "'use strict'; return 17;");
answer Aug 4, 2014 by Vrije Mani Upadhyay
0 votes

For Strict mode, we using use strict to execute

The purpose of use strict is to indicate that the code should be executed in "strict mode".

Strict mode makes it easier to write "secure" JavaScript.

Strict mode changes previously accepted "bad syntax" into real errors.

Strict mode is declared by adding use strict to the beginning of a JavaScript file, or a JavaScript function.

Declared at the beginning of a JavaScript file, it has global scope (all code will execute in strict mode).

Declared inside a function, it has local scope (only the code inside the function is in strict mode).

Example:

"use strict";
function testStrict(){
    var x;
    x = 5; // This does not cause an error. 
}
x = 5; // This causes an error
answer Aug 9, 2014 by Sidharth Malhotra
...