0

I spent a lot of time debugging a program, thinking I couldn't do something when my only mistake was to having switched the case of a variable name.

I can enable strict mode (AKA, no undeclared variable can be used) per file by typing "use strict"; it indeed shows me that I am using a non-existing variable.

How can I enable strict mode globally, or at least for my project's files ?

user96649
  • 471
  • 1
  • 5
  • 22

4 Answers4

1

Because strict mode is selected at the level of a syntactic source text unit, strict mode only imposes restrictions that have local effect within such a source text unit. Strict mode does not restrict or modify any aspect of the ECMAScript semantics that must operate consistently across multiple source text units.

That's what the specification says.

So it's not possible to globally enable strict mode for multiple JavaScript files.

However, you could use a build tool like Gulp. This enables you to combine all your JavaScript files to one single file. In this case, you would only have to enable the strict mode once.

JSON Derulo
  • 9,780
  • 7
  • 39
  • 56
0

Try to use

use strict

Please check the tutorial in w3schools.com https://www.w3schools.com/js/js_strict.asp

josdev
  • 81
  • 1
  • 11
0

What about putting the 'use strict' in app.js as common file. Please make a try.

John Davis
  • 413
  • 5
  • 12
0

Add ng-strict-di attribute to the body tag of your index.html

Here is the documentation: AngularJs Strict Di Mode

Maxwellt
  • 126
  • 5