BeginningJavaScript History and EvolutionBackward Compatibility (Don’t break the web)How to use Modern JavaScript Today Updated?Activating Strict Mode
Beginning
JavaScript History and Evolution
- 1995: Brendan Eich created "Mocha" in 10 days for Netscape Navigator.
- 1996: Renamed to "LiveScript" and then "JavaScript" for marketing.
- 1997: Standardized as ECMAScript (ES1) by ECMA.
- ES5 (2009) and ES6/ES2015 introduced major updates, with ES6 marking the start of annual release cycles.
Backward Compatibility (Don’t break the web)
- JavaScript engines must support the earliest releases to avoid "breaking the web."
- ECMAScript builds on existing features rather than introducing breaking changes (e.g.,
classis syntactic sugar).
- ECMAScript doesn't have entirely new versions, but rather builds upon the existing language with new features released annually
- It means that the TC39 committee can’t have ground-breaking changes and the newer changes are only built on top of existing ones. One such example is with
classas it is not native
How to use Modern JavaScript Today Updated?
- Forward compatibility isn’t possible.
- To use modern features:
- In Development use updated browsers;
- Production often uses Babel for transpilation and polyfills.
- ECMAScript proposals go through 4 stages before becoming part of the specification. Stage 3 features are often implemented in browsers as ESNext.
Activating Strict Mode
- It is not a keyword but a string
“use strict”that is added on top of our JavaScript files, the reason is that only newer browsers can support it and older browser will ignore the string
- It activates the so-called Strict Mode Operating Context
- In strict mode assigning value to a undeclared variable will throw error, which otherwise gets added to the global variable (document or window). This prevents from accidental globals
- The value of
thischanges fromwindowtoundefinedin strict mode
'use strict'; var theVal = 0; thVal = 1; // Will throw error in strict mode if (theVal > 0){ console.log("Hello!"); }
- It prevents use of variable names that might become part of the language in the future like
interfaceor evenlet
"use strict"; var let = 1; // Runs without strict mode
- We can’t
deletevalues in strict mode
const framework = { name: "Next.js", age: 12 } delete framework.name // Not allowed
- The use of
evalwon’t leak out variables. The eval is a function used to run some JavaScript inside a string
"use strict"; eval("var age = 14;") console.log(age); // Not allowed