Skip to content

Latest commit

 

History

History
41 lines (32 loc) · 922 Bytes

File metadata and controls

41 lines (32 loc) · 922 Bytes

What is "use strict"?

  1. A variable must declare using var keyword, which could avoid accidentally creating global variables.
  2. User strict mode STOP this being a global valuable and set "undefined" as default value.
  • Look at below table. In JavaScript, this is unstable and it is different how this is called. In Non-strict mode, this refers a global valuable and most of the case, it is confused and stop being as a global valuable.
    this

Global Scope

Non-strict mode

console.log(this); // Window Object

Strict mode

"use strict";
console.log(this); // Window Object

Function Scope

Non-strict mode

function test(){
    console.log(this);
}
test();// Window object

Strict mode

"use strict";
function test(){
    console.log(this);
}
test();// undefined

"strict mode" set "undefined" as default value.