Skip to content
KodeTrail

Camp 1 · Step 3 of 18

Values, expressions, and errors

How JavaScript evaluates expressions, and how to read its error messages without flinching.

12 min+50 XP

Programs are built from expressions — pieces of code that produce a value. 2 + 2 is an expression. So is "Kode" + "Trail". Understanding "this code becomes a value" is a quiet superpower.

Expressions evaluate

JavaScript

JavaScript works from the inside out: (2000 + 500) becomes 2500, then glues onto the string. Notice + does double duty — addition for numbers, concatenation for strings. That leads to JavaScript's most famous quirk:

JavaScript

"2" + 2 gives "22" — when one side is a string, JavaScript converts the other side and concatenates. Keep quotes for text and bare digits for math, and this will never bite you.

Errors are guides

Run this broken line:

JavaScript

ReferenceError: greeting is not defined — JavaScript's version of "I've never heard of this name." The error type tells you the category, the message names the culprit. Compare:

ErrorUsually means
ReferenceError: x is not definedtypo, or using a name before creating it
SyntaxError: unexpected tokenJavaScript couldn't parse it — often a missing ) or quote
TypeError: x is not a functioncalling something that isn't callable — often a typo like console.lg
Checkpoint

What does console.log("1" + 1) print?

Checkpoint

You see: TypeError: console.lgo is not a function. What happened?