0
What is strict mode and how do you enable it?
ng new my-app --strict
What is strict mode and how do you enable it?
ng new my-app --strict
Strict Mode is a feature in JavaScript that helps you write cleaner, safer, and more secure code by enforcing stricter parsing and error handling rules.
Strict mode eliminates some silent errors and makes them visible (throws errors). It also prevents the use of unsafe or outdated JavaScript features.
You enable strict mode using a simple directive:
"use strict";
x = 10; // Error: x is not defined
function myFunction() {
"use strict";
y = 20; // Error
}
x = 10; // No error (bad practice)
console.log(x);
"use strict";
x = 10; // ReferenceError
"use strict";
a = 5; // Error
function sum(a, a) { } // Error
delete x; // Error
this behaves differently
this is undefined in functions (not global object)If you're using modern JavaScript (ES6 modules), strict mode is automatically enabled.