To enable strict mode in JavaScript it's needed to insert 'use strict' to a script. If I have several scripts, I need to add it to all. Maybe it can be added only once in settings? Not found any examples for now.
P.S. I know about add-ons that add statement to all scripts, it's not very convenient anyway.
Or to use modules, which are strict by default. To tell the JavaScript parser (and VS Code) that a file is a module, add an
importorexportto it. You can have an emptyexportif the file is completely standalone:...although usually, once you adopt modules, you just naturally end up with
importandexportto share functions and such between the modules, so you don't need something synthetic like that (or"use strict";).Modules offer benefits beyond automatically being in strict mode, such as having their own top-level scope (rather than top-level code being in global scope) and, of course, declarative dependencies between files.
More about modules on MDN and in Chapter 13 of my recent book JavaScript: The New Toys.
The problem with doing that is that VS Code's settings have no effect on the JavaScript engine that will ultimately be responsible for parsing and evaluating the code. That's why you need something in the file itself.