Strict Mode is a way to opt in to a restricted variant of JavaScript. It helps you write cleaner code and catch common bugs earlier.
To enable strict mode, add "use strict";
at the beginning of a script or a function:
"use strict";
x = 10; // โ Error: x is not defined
Without strict mode, this would not throw an error:
x = 10; // โ
Allowed in non-strict mode (but bad practice)
function demo() {
"use strict";
let y = 20;
// z = 30; // โ Error: z is not defined
}
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!