Trong strict mode, this ở hàm thông thường là undefined thay vì global object (window/global).
Điều này giúp phát hiện lỗi khi vô tình gọi hàm như function thay vì method.
javascript
function foo() { console.log(this); }
foo(); // non-strict: Window (browser)
'use strict';
function bar() { console.log(this); }
bar(); // strict: undefinedKích hoạt bằng 'use strict'; ở đầu file hoặc hàm.
ES modules tự động bật strict mode.
In strict mode, this inside a regular function is undefined instead of the global object (window/global).
This helps catch bugs when a function is accidentally called as a function rather than a method.
javascript
function foo() { console.log(this); }
foo(); // non-strict: Window (browser)
'use strict';
function bar() { console.log(this); }
bar(); // strict: undefinedEnable with 'use strict'; at the top of a file or function.
ES modules automatically enable strict mode.