~ Markus Persson
Markus Alexej Persson, known by the pseudonym Notch, is a Swedish video game programmer and designer. He is the creator of Minecraft, which is the best-selling video game in history. He founded the video game development company Mojang Studios in 2009. Persson began developing video games at an early age.
~ Douglas Crockford
Douglas Crockford is an American computer programmer who is involved in the development of the JavaScript language. He specified the data format JSON, and has developed various JavaScript related tools such as the static code analyzer JSLint and minifier JSMin.
Netscape
Founder of Brave, Mozilla
Creator of JavaScript (1995)
JavaScript was invented by Brendan Eich in 1995.
It was developed for Netscape 2, and became the ECMA-262 standard in 1997.
After Netscape handed JavaScript over to ECMA, the Mozilla foundation continued to develop JavaScript for the Firefox browser. Mozilla's latest version was 1.8.5. (Identical to ES5)
Microsoft reverse-engineered JavaScript and called it <JScript/>
Introduced it in π© Internet Explorer 3
And created two similar but not identical languages π€― caused browser chaos till June 15, 2022 when IE died. π
ES2 and ES3 β¦ π©
Browsers were inconsistent π€―, devs relied on hacks and jQuery to deal with differences
Google created V8 for its Chrome browser, and both were first released in 2008. The lead developer of V8 was π₯Έ Lars Bak, and it was named after the powerful car engine.
For several years, Chrome was π faster than other browsers at executing JavaScript.
It compiled JS to machine code using JIT
πͺ Parses it (turns it into a structure the engine can understand)
π οΈ Compiles it to machine code (not just bytecode or interpretedβthis is fast, native code)
π Optimizes the code at runtime (using techniques like inline caching and just-in-time compilation).
Big update π€
strict
mode
Object.defineProperty
JSON
support
Became widely adopted and laid the foundation for modern JS
Object.defineProperty(obj, prop, descriptor)
----------------------------------------------
const object = {};
Object.defineProperty(object, "clarity", {
value: 42,
writable: false,
});
object.clarity = 77; //// Throws an error in strict mode
console.log(object.clarity);// Expected output: 42
Another update π
let
and const
Arrow functions () => {}
(import/export)
Promises
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate limitations in usage
Arrow functions don't have their own bindings to this, arguments, or super, and should not be used as methods.
Arrow functions cannot be used as constructors. Calling them with new throws a TypeError. They also don't have access to the new.target keyword.
function test () {
console.log(arguments)
}
test("ddd")
/*
Arguments ['ddd', callee: Ζ, Symbol(Symbol.iterator): Ζ]
0:"ddd",
callee: Ζ test()
length:1
Symbol(Symbol.iterator)
[[Prototype]]: Object
*/
const myObject = {
name: 'Alex',
printAsync: function(){
setTimeout(() => {
console.log(this.name)
},1000)
}
}
const myObject = {
name: 'Alex',
printAsync: function(){
setTimeout(() => {
console.log(this.name)
},1000)
}
}
var myObject = {
name: "Alex",
printAsync: function printAsync() {
var _this = this;
setTimeout(function () {
console.log(_this.name);
}, 1000);
}
};
var myObject = {
name: "Alex",
printAsync: function printAsync() {
var _this = this;
setTimeout(function () {
console.log(_this.name);
}, 1000);
}
};
Template literals
Destructuring
Default parameters
π·π» Yearly updates
async/await
Optional chaining (?.)
Nullish coalescing (??)
BigInt, Array.flat(), Object.entries(), Object.groupBy()... etc
Top-level await
β Runs everywhere: browsers, servers (Node.js), desktops (Electron), mobile (React Native)
β Powers most modern web apps (React, Angular, Vue)
β Competes with many languages but remains the king of the web π
π± What Does That Mean?
π© One call stack
JS has one call stack, meaning it can do one thing at a time.
π© No multi-threading (like in C++ or Java)
so it executes code line-by-line, top to bottom.
π₯ Asynchronous code
π Fetching data from an API?
π Waiting 5 seconds with setTimeout?
π§βπ» Responding to user clicks?
...etc
JavaScript works with the help of its environment (like the browser or Node.js), and the event loop manages how asynchronous operations are handled.
Promise.then()
catch
finally
queueMicrotask
queueMicrotask(callback) schedules the callback to run at the end of the current JavaScript execution context, but before the next event loop tick.
In simpler terms, it puts the task in the microtask queue, which is processed immediately
after the current
function finishes and before any setTimeout, setInterval
, or I/O events.
It's similar to Promise.resolve().then(...)
, but more direct and
slightly faster..
A Pure Function is a function (a block of code) that always returns the same result if the same arguments are passed.
function add(a, b) {
return a + b;
}
console.log(add(2, 3));
console.log(add(2, 3));
In computing, memoization or memoisation is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls to pure functions and returning the cached result when the same inputs occur again.
const foo = (x) => {
console.log("very long calculation of x")
return x * 2;
}
const memoize = function (f) {
const cache = {};
return function (x) {
return cache[x] ? cache[x] : cache[x] = f(x)
}
}
const memoizedFoo = memoize(foo);
const res1 = memoizedFoo(42) // 84
// very long calculation of x
// cache = {}
const res2 = memoizedFoo(42) // 84
// cache = { 42: 84 }
<CustomElement onData={...}/>
customElement.prototype.getData = function (url) {
if (this.cache[url]) {
this.data = this.cache[url];
this.dispatchEvent(new Event("load"));
} else {
fetch(url)
.then((result) => result.arrayBuffer())
.then((data) => {
this.cache[url] = data;
this.data = data;
this.dispatchEvent(new Event("load"));
});
}
};
element.addEventListener("load", () => console.log("Loaded data"));
console.log("Fetching dataβ¦");
element.getData("ht tp://example.com/data.bin");
console.log("Data fetched");
customElement.prototype.getData = function (url) { if (this.cache[url]) { this.data = this.cache[url]; this.dispatchEvent(new Event("load")); } else { fetch(url) .then((result) => result.arrayBuffer()) .then((data) => { this.cache[url] = data; this.data = data; this.dispatchEvent(new Event("load")); }); } };
Fetching dataβ¦
Data fetched
Loaded data
customElement.prototype.getData = function (url) { if (this.cache[url]) { this.data = this.cache[url]; this.dispatchEvent(new Event("load")); } else { fetch(url) .then((result) => result.arrayBuffer()) .then((data) => { this.cache[url] = data; this.data = data; this.dispatchEvent(new Event("load")); }); } };
Fetching dataβ¦
Loaded data
Data fetched
customElement.prototype.getData = function (url) {
if (this.cache[url]) {
this.data = this.cache[url];
this.dispatchEvent(new Event("load"));
} else {
fetch(url)
.then((result) => result.arrayBuffer())
.then((data) => {
this.cache[url] = data;
this.data = data;
this.dispatchEvent(new Event("load"));
});
}
};
customElement.prototype.getData = function (url) {
if (this.cache[url]) {
return this.data = this.cache[url];
} else {
return fetch(url)
.then((result) => result.arrayBuffer())
.then((data) => {
this.cache[url] = data;
this.data = data;
});
}
};
customElement.prototype.getData = function (url) {
if (this.cache[url]) {
return this.data = this.cache[url];
} else {
return fetch(url)
.then((result) => result.arrayBuffer())
.then((data) => {
this.cache[url] = data;
this.data = data;
});
}
};
const f1 = () => Promise.resolve(42)
const f2 = () => 42
f1()
// Promise {: 42}
f2()
// 42
await Promise.resolve(f1())
await Promise.resolve(f2())
//42
//42
customElement.prototype.getData = function (url) {
if (this.cache[url]) {
this.data = this.cache[url];
this.dispatchEvent(new Event("load"));
} else {
fetch(url)
.then((result) => result.arrayBuffer())
.then((data) => {
this.cache[url] = data;
this.data = data;
this.dispatchEvent(new Event("load"));
});
}
};
element.addEventListener("load", () => console.log("Loaded data"));
console.log("Fetching dataβ¦");
element.getData();
console.log("Data fetched");
customElement.prototype.getData = function (url) { if (this.cache[url]) { this.data = this.cache[url]; this.dispatchEvent(new Event("load")); } else { fetch(url) .then((result) => result.arrayBuffer()) .then((data) => { this.cache[url] = data; this.data = data; this.dispatchEvent(new Event("load")); }); } };
Fetching dataβ¦
Loaded data
Data fetched
customElement.prototype.getData = function (url) { if (this.cache[url]) { this.data = this.cache[url]; this.dispatchEvent(new Event("load")); } else { fetch(url) .then((result) => result.arrayBuffer()) .then((data) => { this.cache[url] = data; this.data = data; this.dispatchEvent(new Event("load")); }); } };
Fetching dataβ¦
Data fetched
Loaded data
customElement.prototype.getData = function (url) { if (this.cache[url]) { queueMicrotask(() => { this.data = this.cache[url]; this.dispatchEvent(new Event("load")); }); } else { fetch(url) .then((result) => result.arrayBuffer()) .then((data) => { this.cache[url] = data; this.data = data; this.dispatchEvent(new Event("load")); }); } };
Fetching dataβ¦
Loaded data
Data fetched
console.log(" π·π» console ")
setTimeout(() => console.log(" π setTimeout "), 0)
Promise.resolve().then(() => console.log(" π§΅ Promise "))
console.log(" π·π» console2 ")
console.log(" π·π» console ")
setTimeout(() => console.log(" π setTimeout "), 0)
Promise.resolve().then(() => console.log(" π§΅ Promise "))
console.log(" π·π» console2 ")
/// π·π» console
/// π·π» console2
/// π§΅ Promise
/// π setTimeout
JS runs in browser with V8 + Web APIs
Node.js runs JS in server with V8 + libuv for async ops
Feature | JS | Node |
---|---|---|
Environment | Runs in the browser | Runs on the server |
Engine | V8 ( libuv like WebAPI) | V8 + libuv (for I/O) |
Macro tasks | setTimeout, setInterval, setImmediate* | Same, plus setImmediate |
Micro tasks | Promise.then, MutationObserver | Promise.then, process.nextTick |
APIs | DOM, Web APIs (fetch, event handlers) | fs, http, etc. (via libuv) |
Queue | Managed by the browser | Managed by libuv + internal Node scheduler |
Layer | Component | Description |
---|---|---|
JS Engine | V8 (Chrome), SpiderMonkey (Firefox), JavaScriptCore (Safari) | Executes your JavaScript code |
Browser Engine | Blink (Chrome), Gecko (Firefox), WebKit (Safari) | Handles DOM, rendering, layout, and event loop |
Event Loop | Built into the browser engine | Orchestrates tasks, callbacks, and events |
Async APIs | Web APIs (DOM timers, Fetch, etc.) | Expose async behavior to JS β implemented in C++ or Rust (libuv like) |
May the <F=ma> be with You
JavaScript Types (as of ECMAScript 2023)
JS has two main categories of types
Primitive: string, number, boolean, null, undefined, bigint, symbol
Reference: object, array, function, date, map, set
" 5" + 1="51"
"5" - 1 = 4