Episode 1 — Fundamentals / 1.13 — Introduction to JavaScript
1.13 — Introduction to JavaScript: Quick Revision
Compact cheat sheet. Print-friendly.
How to use this material (instructions)
- Skim top-to-bottom before interviews or labs.
- If a row feels fuzzy — reopen the lesson:
README.md→1.13.a…1.13.h. - Drills —
1.13-Exercise-Questions.md. - Polished answers —
1.13-Interview-Questions.md.
1.13.a What is JavaScript?
| Concept | One-liner |
|---|---|
| JS role | Behavior — logic, events, DOM updates, network, apps |
| With HTML/CSS | Structure / presentation / behavior |
| ECMAScript | The language spec; “JS” = ES + host APIs |
| Not Java | Unrelated languages |
1.13.b Where JS runs
Browser → DOM + Web APIs + window/document
Node.js → V8 + files/HTTP/process (no document)
| Term | Meaning |
|---|---|
| Runtime | Engine + host APIs + event loop (conceptually) |
| V8 | Google’s JS engine (Chrome, Node) |
1.13.c <script> loading
| Attribute | Behavior |
|---|---|
| (none, classic) | Fetch + run can block HTML parse |
defer | Parallel fetch; run after parse; ordered |
async | Parallel fetch; run ASAP; order not guaranteed between async scripts |
type="module" | ES modules; deferred; import/export |
Default choice for apps: <script src="app.js" defer></script> or type="module".
1.13.d Console
| Method | Use |
|---|---|
console.log | General output (multiple args OK) |
console.warn / error | Severity + stack styling |
console.table | Tabular data |
| REPL | Type expressions at > in Console |
Errors: read name + first stack frame first.
1.13.e Variables & scope
| Keyword | Reassign? | Scope | Hoisting / TDZ |
|---|---|---|---|
const | No | Block | TDZ |
let | Yes | Block | TDZ |
var | Yes | Function | Hoisted; no TDZ |
Rule: const → let → avoid var.
const object: cannot reassign binding; can mutate properties.
1.13.f Naming
| Style | Example | Use |
|---|---|---|
| camelCase | firstName | variables, functions |
| PascalCase | UserCard | classes / some components |
| SCREAMING_SNAKE | API_URL | fixed config constants |
Booleans: is*, has*, should*, can*.
1.13.g Types
Primitives (ES6+)
number · string · boolean · null · undefined · bigint · symbol
typeof cheatsheet
| Expression | Result |
|---|---|
typeof 1 | "number" |
typeof "x" | "string" |
typeof true | "boolean" |
typeof undefined | "undefined" |
typeof null | "object" (quirk) |
typeof {} | "object" |
typeof NaN | "number" |
Checks: x === null · Array.isArray(x) · prefer === / !==
null vs undefined: intentional empty vs not set / missing.
1.13.h Mini programs
const n = Number(prompt("Number?")); // string → number
if (prompt("x") === null) { /* cancelled */ }
alert(`Hello, ${name}!`); // template literal
Production: replace prompt/alert with forms + DOM.
One-liner definitions
| Term | One-liner |
|---|---|
| DOM | Live tree of HTML nodes in memory |
| Engine | Executes JS (V8, SpiderMonkey, JSC) |
| Node.js | Server-side JS runtime (no DOM by default) |
| Primitive | Non-object atomic value |
| Reference type | Object (stored by reference) |
| Block scope | { } limits visibility of let/const |
| TDZ | Cannot access let/const before declaration line |
| Hoisting | var declaration lifted; initializes as undefined |
| Template literal | Backtick string with ${expr} interpolation |
| Coercion | Implicit type conversion (==, some operators) |
Master workflow
- HTML loads → parser hits
<script>(mind defer/async/module). - JS runs in a host (browser: DOM; Node: core modules).
- Use
const/let, meaningful names,===for checks. - Know types (
typeofquirks, array check, null vs undefined). - Debug with Console + errors; grow into Sources breakpoints.
- I/O learning:
prompt→ string →Number()+ validation.
End of 1.13 quick revision.