JavaScript - what does 'use strict' do ?

0 points
Asked by:

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:

"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.

â€ïžđŸ’» 🙂