DEV Community

Shashi Bhushan Kumar
Shashi Bhushan Kumar

Posted on

What is "use strict" in JavaScript, and how does it help prevent common mistakes?

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);
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

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)