Variables & console.log

A free sample lesson from JavaScript Basics

The idea

A labeled box that can hold anything - swap what's inside any time you like, but the label on the box never changes.

What it actually is

A variable is a labeled box that stores a value so your program can remember and reuse it. console.log(...) is how JavaScript shows something on screen - it's the exact same job Python's print() does, just a different name.

How you write it

let name = value;
console.log(name);

A worked example

let dinosaurName = "Rex";
console.log(dinosaurName);

Line 1 creates a box labeled "dinosaurName" and puts the text "Rex" inside it. Line 2 asks JavaScript to show whatever is in that box right now - so "Rex" gets printed.

const favoriteGame = "Space Race";
console.log(favoriteGame);

const works just like let, except the box is locked once filled - you can't put a different value in later. Use const for values that should never change, let for ones that will.

Mistakes children actually make

Mistake 1: writing petName = Max; with no quotes around Max - JavaScript thinks Max is another variable (that doesn't exist) and crashes with "Max is not defined." Text always needs quotes: "Max". Mistake 2: writing console.log petName; with no parentheses - console.log is a function, so what you're printing always goes inside ( ), the same way Python's print(...) needs its parentheses too. Mistake 3: trying to put a new value into a const after it's created - const favoriteGame = "Chess"; favoriteGame = "Checkers"; crashes with "Assignment to constant variable" because the box is locked; use let instead if the value needs to change later.

Then they try it

In the app this lesson continues with the animated explanation, spoken aloud, and then the practice: Create a variable called petName set to "Max", then print it with console.log. The editor runs your child’s real code and checks the result, with their coding buddy reacting to what they wrote.

Try it free