<aside> ⚠️ I’m still reading…
</aside>
<aside> ⚠️ This note serves as a reminder of the book's content, including additional research on the mentioned topics. It is not a substitute for the book. Most images are sourced from the book or referenced.
</aside>
<aside> 🚨 I've noticed that taking notes on this site while reading the book significantly extends the time it takes to finish the series. I've stopped noting everything, as in previous chapters, and instead continue reading by highlighting or hand-writing notes and use . I plan to return to this series when I have more time.
</aside>
Compiled vs. Interpreted Code
var a = 2;
will be tokenized as var
, a
, =
, 2
and ;
.var a = 2
may start with a top-level node called VaraibleDeclaration
, with a child node called Identifier
(a
),…Syntax Errors from the Start: How JS knows ."Hi"
without printing “greeting”? ← It reads whole code first!
var greeting = "Hello";
console.log(greeting);
greeting = ."Hi"; // SyntaxError: unexpected token .
Early Errors: How JS know duplicated parameters “greeting” (becauase of "use strict"
) without printing “Howdy”? ← It reads the whole code first!
console.log("Howdy");
saySomething("Hello","Hi");
// Uncaught SyntaxError: Duplicate parameter name not
// allowed in this context
function saySomething(greeting, greeting) {
"use strict";
console.log(greeting);
}
Hoisting: How JS know “greeting” is a block-scoped variable whereas there is var greeting...
? ← It reads the whole code first!
Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution. Ref.
function saySomething() {
var greeting = "Hello";
{
greeting = "Howdy"; // error comes from here
let greeting = "Hi"; // defines block-scoped variable "greeting"
console.log(greeting);
}
}
saySomething();
// ReferenceError: Cannot access 'greeting' before initialization