Asked 7 years ago
7 Jan 2017
Views 932
web-api

web-api posted

what is use of "use strict" in JavaScript ?

what is use of "use strict" in JavaScript ?
i got many library or code in JavaScript which have used "use strict"

(function(){
  "use strict";

 
})();


so "use strict" stand for what ? how to use "use strict "? and what is reason behind for use of "use strict" ?
Phpworker

Phpworker
answered Nov 30 '-1 00:00

"use strict" in JavaScript apply strict rule of coding so JavaScript will generate error of every mis coding and mis use of syntax of etc. which will not generate error in normal case.
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

"use strict" means more strict restriction for coding .
it will generate more error and more throw exception . it prevent to take unsafe action .

check here more detail


(function(test){
 "use strict"; // enable strict mode within this function
var value='t';
delete value;
 })

it will throw error ::
Uncaught SyntaxError: Delete of an unqualified identifier in strict mode.
but without "use strict"

(function(test){
var value='t';
delete value;//return false 
 })

delete bar return false only not throw any error .because strict mode is not on
Post Answer