Languages

JavaScript - what does 'use strict' do ?

0 points
Asked by:
Dirask Community
5610

What does it mean that "use strict" defines that JavaScript code should be executed in "strict mode" ?

What is 'strict mode'?

1 answer
0 points
Answered by:
Dirask Community
5610

"use strict" directive is actually a literal expression that tells JavaScript that the code should be executed in a strict mode. It was presented in ES5 (ignored by earlier versions of JavaScript).

What strict mode does:

  • you cannot use undeclared variables inside it,
  • it changes previously accepted "wrong┬ásyntax" into┬áerrors,
  • it doesn't allow┬ámistyping a variable name (which outside the strict mode creates a new global variable),
  • any assignment to a non-writable / getter-only / non-existing property or┬ánon-existing variable/object┬áwill throw an error.

So basically strict mode makes it easier to write secure code in JavaScript.

0 comments Add comment
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join