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)

  1. Skim top-to-bottom before interviews or labs.
  2. If a row feels fuzzy — reopen the lesson: README.md1.13.a1.13.h.
  3. Drills1.13-Exercise-Questions.md.
  4. Polished answers1.13-Interview-Questions.md.

1.13.a What is JavaScript?

ConceptOne-liner
JS roleBehavior — logic, events, DOM updates, network, apps
With HTML/CSSStructure / presentation / behavior
ECMAScriptThe language spec; “JS” = ES + host APIs
Not JavaUnrelated languages

1.13.b Where JS runs

Browser  → DOM + Web APIs + window/document
Node.js  → V8 + files/HTTP/process (no document)
TermMeaning
RuntimeEngine + host APIs + event loop (conceptually)
V8Google’s JS engine (Chrome, Node)

1.13.c <script> loading

AttributeBehavior
(none, classic)Fetch + run can block HTML parse
deferParallel fetch; run after parse; ordered
asyncParallel 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

MethodUse
console.logGeneral output (multiple args OK)
console.warn / errorSeverity + stack styling
console.tableTabular data
REPLType expressions at > in Console

Errors: read name + first stack frame first.


1.13.e Variables & scope

KeywordReassign?ScopeHoisting / TDZ
constNoBlockTDZ
letYesBlockTDZ
varYesFunctionHoisted; no TDZ

Rule: constlet → avoid var.

const object: cannot reassign binding; can mutate properties.


1.13.f Naming

StyleExampleUse
camelCasefirstNamevariables, functions
PascalCaseUserCardclasses / some components
SCREAMING_SNAKEAPI_URLfixed config constants

Booleans: is*, has*, should*, can*.


1.13.g Types

Primitives (ES6+)

number · string · boolean · null · undefined · bigint · symbol

typeof cheatsheet

ExpressionResult
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

TermOne-liner
DOMLive tree of HTML nodes in memory
EngineExecutes JS (V8, SpiderMonkey, JSC)
Node.jsServer-side JS runtime (no DOM by default)
PrimitiveNon-object atomic value
Reference typeObject (stored by reference)
Block scope{ } limits visibility of let/const
TDZCannot access let/const before declaration line
Hoistingvar declaration lifted; initializes as undefined
Template literalBacktick string with ${expr} interpolation
CoercionImplicit type conversion (==, some operators)

Master workflow

  1. HTML loads → parser hits <script> (mind defer/async/module).
  2. JS runs in a host (browser: DOM; Node: core modules).
  3. Use const/let, meaningful names, === for checks.
  4. Know types (typeof quirks, array check, null vs undefined).
  5. Debug with Console + errors; grow into Sources breakpoints.
  6. I/O learning: promptstringNumber() + validation.

End of 1.13 quick revision.