Search code examples
javascriptangularjsstrict-mode

Usage of 'use strict' with AngularJS


I am using AngularJS 1.6, Can i use use strict with my Controller, Directives, services, etc.

Is it a good practice using 'use strict' with AngularJS app?


Solution

  • use strict generally is a good idea, but there's a bunch of circumstances where it's unnecessary.

    For example, if you use a typing system, most typing systems will automatically add use strict. This is true for flow or typescript.

    If you use es6 modules, 'use strict' is also enabled by default.

    If you use neither, use strict is still a good idea. It definitely doesn't hurt.

    Aside: If you care about the security that use strict gives you, you might care about using a typing system like typescript or upgrade your angular version to something much more recent. Although I recognize it's not always an option with large legacy code bases.