How do I enable use strict ? By default, the mode is disabled for compatibility with the old code, it is recommended to always enable this mode in your projects. To switch the code to modern mode, it is enough to write at the beginning of the file with JS code:
"use strict" ;
'use strict' ;
It is also possible to use this mode inside functions, then it will only apply to the code inside the current block. However, it is easier to specify the directive for the entire file. The directive must be specified at the very beginning of the file or function, otherwise it will not work (it can be placed after comments). After enabling the mode, it cannot be disabled for the current section or file. It is important to remember that if using the the console in browser to test your code , you must also enable mode in a similar way if you want to test your code in strict mode.
Above it was found out why use use strict - it is recommended to use it everywhere, but in the future it is possible to automatically enable strict mode by default. For example, already now you can use new JS structures - classes and modules in which this mode is enabled by default. The advent of strict mode will allow JS to improve in the future.
Enabling strict mode imposes a number of restrictions, in particular, it is not allowed in the new mode:
- duplicate parameter name ;
- using variable and objects without declaration ;
- deleting a variable, objects, functions, properties that cannot be deleted ;
- use of octal numeric literals (010) and escape characters ("\ 010") ;
- write to read-only or get-only property ;
- use words eval, arguments ;
- with declaration ;
- create variables with eval in the scope from which it was called .
When writing code, it is also important to remember the new reserved words and not use them in your code: publicv , static , let , package , private , implements , interface , yield , protected .
- IT / Misc 08.07.21 How to make a free translation for a website without an API, translate documents in Google Translate
- IT / Misc 06.07.21 How to make a subscription button on a website, a subscriber base and automatic mailing
- Food / Misc 06.07.21 How to quickly cook delicious fried pies with potatoes and onions
- IT / Misc 04.07.21 Caching - create, load and reset. Where to store the cache, methods and types of caching
- IT / Database 03.07.21 Custom NoSQL - storing data in files and not only in a database. Storing settings, small data and caching files