What is "use strict" in JavaScript?
"use strict" is a special statement that makes JavaScript run in strict mode.
Strict mode makes JavaScript:
- More safe
- More careful
- More error-friendly
Why Do We Use It?
Because normal JavaScript sometimes allows mistakes silently.
Strict mode:
- Stops undeclared variables
- Prevents duplicate parameter names
- Catches common bugs early
Simple Example
β Without "use strict"
x = 10;
console.log(x);
This works.
But waitβ¦
We never declared x using let, var, or const.
JavaScript silently creates a global variable.
That can cause problems later.
β
With "use strict"
"use strict";
x = 10;
Now JavaScript gives an error.
Because x was not declared.
One-line Summary
"use strict" helps prevent common mistakes by making JavaScript stricter.
Top comments (0)