It is used to enable strict mode, which enforces a stricter set of rules for writing JavaScript code.
Purpose of "use strict":
Prevents accidental errors - It throws errors for common coding mistakes, such as assigning values to undeclared variables.
Improves performance - Some optimizations are enabled under strict mode since the code behaves in a predictable manner.
Disallows unsafe actions - It forbids certain features that are prone to errors, like using with statements.
Simplifies debugging - Errors are detected earlier, reducing debugging time.
Promotes future-proof code - It helps prepare codebases for future JavaScript versions by enforcing stricter standards.
Why is it used?
To avoid subtle bugs that are hard to detect in non-strict mode.
To enforce a cleaner and more secure coding standard.
To make the code easier to understand and maintain.