Free Handbook · Runs in your browser

Fundamentals

Variables with let and const, the seven primitive types and typeof, coercion and conversion, output with template literals, every operator, precedence, and the two errors — ReferenceError and TypeError — that beginners hit in their first hour.

0 / 111 lessons🔥 0 day streak
ShareXLinkedIn

Module 01 · what you'll be able to do

  • Declare variables with const by default and let when they change — and know why var is avoided
  • Name the primitive types and check them with typeof
  • Predict what "5" + 3 and "5" - 3 give, and convert types on purpose
  • Build strings with template literals and print with console.log
  • Use arithmetic, comparison, logical and assignment operators, including ===, ?? and ?.
01

Variables: let, const and why not var

A variable is a name for a value. const makes a name that cannot be reassigned; let makes one that can. Default to const — it tells the reader "this does not change" — and reach for let only for counters and accumulators. var is the 1995 version: it ignores block scope and is hoisted in a way that hides bugs, so modern code does not use it.

javascriptEdit it. ⌘/Ctrl + Enter runs.
You should see
Ada 2
{ name: 'Grace' }
undefined everywhere
3 Ada
Your turn
Declare a const and try to reassign it. Read the error. Then change it to let.
Error you will hit

TypeError: Assignment to constant variable

javascript
const total = 10
total = 20
Uncaught TypeError: Assignment to constant variable.
    at your code:2
Why the engine said that

You declared total with const, which promises it will never be reassigned. The engine holds you to it.

The fix

If the value genuinely changes, declare it with let. If you only meant to change a property inside an object or array, that is allowed with const — see above.

javascript
let total = 10
total = 20
console.log(total)
Error you will hit

ReferenceError: x is not defined

javascript
const price = 100
console.log(prcie * 2)
Uncaught ReferenceError: prcie is not defined
    at your code:2
Why the engine said that

The engine looked for a variable called prcie and there is none — a typo. JavaScript is case-sensitive too: Price and price are different names.

The fix

Read the name in the error character by character. Editors underline undefined names as you type; use one.

02

Data types and typeof

JavaScript has seven primitive types — number, string, boolean, undefined, null, bigint, symbol — and one object type that covers everything else (arrays, functions, dates, Maps). typeof tells you which you have, with one famous mistake baked in: typeof null is "object", a bug from 1995 that can never be fixed because too much code depends on it.

javascriptEdit it. ⌘/Ctrl + Enter runs.
You should see
number number number
string string string
boolean undefined bigint symbol
object
object object function
true false
undefined null true false
Infinity -Infinity NaN
0.30000000000000004 false
9007199254740991 9007199254740992
9007199254740994n
Your turn
Print typeof NaN. Then check NaN === NaN and fix it with Number.isNaN.
TypeExampletypeofNotes
number42, 3.14, NaN"number"64-bit float. Integers exact to 2⁵³.
string"hi", `hi ${x}`"string"Immutable. UTF-16.
booleantrue, false"boolean"
undefinedlet x"undefined""no value yet". What missing properties and no-return functions give.
nullnull"object" (!)"deliberately empty". You assign it.
bigint10n"bigint"Arbitrary size. Cannot mix with number.
symbolSymbol("id")"symbol"Unique keys. Module 09.
object{}, [], () => {}"object" / "function"Everything else. Module 03, 08.
03

Coercion and conversion: "5" + 3

JavaScript converts types for you when an operator gets mixed inputs — that is coercion, and it is the source of most "JavaScript is weird" screenshots. The rules are small: + with any string makes a string; every other arithmetic operator makes numbers; == coerces before comparing, === does not. Learn the rules, then avoid relying on them: convert explicitly with Number(), String(), Boolean().

javascriptEdit it. ⌘/Ctrl + Enter runs.
You should see
53 53 53 33 123
2 10 5 NaN
42 NaN 0 0 NaN
42 3.5 31
42 42 42 3.14
false false true true false
true
true true true
true true true true
false false false
Your turn
Read "10" + 5 - 2 left to right and predict the answer before running it.
The two rules to memorise
1. + is the only operator that prefers strings. 2. Use === and !== always; the one acceptable == is x == null, which checks for both null and undefined at once.
Quick check

What does "3" * "4" evaluate to?

04

Output and input

console.log is your window into a program. It takes any number of values, prints them space-separated, and shows objects and arrays structurally. Template literals are the right way to build a message. Input depends on where you run: prompt() in a browser, process.argv or readline in Node, and a form field in a real app — none of which exist in this sandbox, so the input examples are static.

javascriptEdit it. ⌘/Ctrl + Enter runs.
You should see
Name: Ada Age: 36
Ada is 36 and knows 2 languages
Next year: 37. Upper: ADA
Line one
Line two
{ name: 'Ada', age: 36 } [ 'JS', 'Python' ]
goes to stderr
a warning
[ { a: 1, b: 2 }, { a: 3, b: 4 } ]
Tab:	Quote:" Backslash:\ Unicode: é
single "with" double double 'with' single
javascriptinput.js
// Browser: a blocking dialog (fine for learning, never for real apps)
const answer = prompt("What is your name?")
alert(`Hello, ${answer}`)

// Node: command-line arguments
//   node input.js Ada 36
const [, , name, age] = process.argv
console.log(name, Number(age))

// Node: read a line from the terminal
import readline from "node:readline/promises"
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
const city = await rl.question("City? ")
rl.close()

Input is environment-specific. Note that prompt always returns a stringprompt("Age?") + 1 is the coercion bug from the last lesson in the wild.

05

Operators

javascriptEdit it. ⌘/Ctrl + Enter runs.
You should see
9 5 14 3.5 1 49
3 -3 -1
32
true true true true true
yes false default empty
false true false
10 0  fallback
Ada undefined undefined
adult
{ retries: 3, debug: false }
number true true
{ name: 'Ada', role: 'admin' }
Your turn
Why is "10" < "9" true? Fix the comparison so it compares numbers.
Three modern operators worth loving
?? for defaults that must keep 0 and "" (port ?? 3000), ?. for reaching into data that might be missing (res.data?.items?.[0]), and ... for copying and merging (Module 09). They replace pages of defensive ifs.
06

Precedence and associativity

When operators mix, precedence decides which binds tighter (* before +) and associativity decides the direction for equal precedence (most left-to-right; ** and assignment right-to-left). You need to know a handful; for everything else, add parentheses — they cost nothing and the next reader will thank you.

javascriptEdit it. ⌘/Ctrl + Enter runs.
You should see
14 20
512 64
3 9
true false
true
2 number
5 5
33 16
Two traps
1 < 2 < 3 does not mean "between": it evaluates left to right and compares a boolean. Write 1 < x && x < 3. -2 ** 2 is a SyntaxError in real JavaScript because it is ambiguous; write (-2) ** 2 or -(2 ** 2).
Precedence (high → low)Operators
Grouping( )
Member, call, optional. [] () ?.
Unary! - typeof ++ await
Power** (right-to-left)
Multiplicative* / %
Additive+ -
Comparison< > <= >= instanceof in
Equality=== !==
Logical&& then || then ??
Ternary, assignment?: = += (right-to-left)
07

Keywords, identifiers and strict mode

An identifier is a name you choose: letters, digits, _ and $, not starting with a digit, case-sensitive. Reserved words (class, function, return, let…) cannot be used as names. Strict mode — on automatically inside modules and classes, or with "use strict" at the top of a file — turns several silent mistakes into errors, and is what every modern codebase runs under.

javascriptEdit it. ⌘/Ctrl + Enter runs.
You should see
dollar is allowed so is underscore digits after
ReferenceError
1 2
Reserved words
break case catch class const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield await enum. Also avoid shadowing globals like name, length, undefined.
Strict mode
Forbids undeclared assignments, duplicate parameter names, octal literals, and makes this undefined in plain functions instead of the global object. On by default in ES modules and classes.
JuniorWhat is the difference between let, const and var?

let and const are block-scoped and not usable before their declaration (the temporal dead zone); const additionally cannot be reassigned. var is function-scoped, hoisted as undefined, and can be redeclared — which is why it is avoided. Default to const, use let for values that change.

What they are really testing: Whether you know why modern code looks the way it does, not just the syntax.

Finish the JavaScript handbook, then get hired

Sit the exam for your certificate, run your resume through the ATS checker, and see the jobs that ask for exactly this.

Check my resume
Found this course useful? Share it.
ShareXLinkedIn

Comments

0

Join the conversation. Sign in to leave a comment — we'd love to hear your thoughts.