9 ms·
In a similar vein to "use strict" we could create a new directive that disallows JS features like var, prototype, == (in favor of ===). Modules with this new di
by MH15 2y ago
In a similar vein to "use strict" we could create a new directive that disallows JS features like var, prototype, == (in favor of ===). Modules with this new directive at the top of the file would be executed under these new rules. You'd be able to create new (maybe lighter weight) JS interpreters that only target this subset.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- para_parolu 2y agoI don’t think anyone uses var anymore. Linters and prettier are doing a good job keeping codebase consistent. Operator == has a valid use case (null or undefined check) but rarely allowed as well. But I wouldn’t mind to have language without legacy.
- bguebert 2y agoIt's kinda ironic to post that on a site that uses var in its javascript
- wruza 2y agoI use var, together with let and const, where appropriate. What’s the problem with var I don’t get it.
- sandreas 2y agovar is global scope, const is block scoped... <script> var x = 1; if(x < 5) { // now y is global (window.y can be accessed everywhere) // using const y = x * 2 would be inaccessible outside the if block var y = x * 2; console.log('double x is: " + y); } </script> Besides that, var is "pulled" upwards, as if it was the first line in the function. That may have side effects.
- purple-leafy 2y agoprototype is super useful