Have you heard about Hack Frontend Community?Join us on Telegram!
Practice JS Problems

JavaScript Strict Mode: What use strict Actually Does

Strict mode in JavaScript is a special operating mode that helps write safer and better quality code. By enabling it, you activate additional checks and restrictions that prevent common errors.

What Does Strict Mode Change?

  • Prohibits using undeclared variables.
"use strict";
x = 10; // Error: variable not declared
  • Prohibits deleting variables, functions or objects.
"use strict";
delete x; // Error: cannot delete variable or function
  • Restricts this in functions. Without strict mode:
function showThis() {
  console.log(this); // `this` refers to global object (window in browser)
}

With strict mode:

"use strict";
function showThis() {
  console.log(this); // `this` will be undefined
}
  • Prevents using reserved words. Words like implements, interface, package cannot be used as variables or function names.
Practice JS Problems

By continuing to use the platform, you accept the terms of the Privacy Policy and the use of cookies.