Without notes, state yesterday’s main idea and one unresolved question.
Values, types, and variables
JavaScript Foundations I
Objective
Represent data accurately and inspect its type.
Variables are measured signals, functions are reusable circuit blocks, and control flow determines which path becomes active.
- strings, numbers, booleans
- null and undefined
- const versus let
Why this matters
Today you write your first program. Everything until now — terminal, HTML, CSS, Git — was the workshop and the materials. From today you control behaviour, and behaviour starts with data: a resistance value, a stock count, whether a part is available. By the end of the hour you can store a value under a name, print it, and ask JavaScript what kind of thing it is.
That last part matters more than it sounds. Most beginner bugs are not logic errors. They are a
value quietly being the wrong type — the text "10" where the number 10 was meant.
Running a JavaScript file
JavaScript is the language you use for the rest of this course. Node.js, installed and verified on Day 2, runs JavaScript files on your own machine.
Make a file called values.js with one line in it:
console.log("Hello from Node");
Then, from the folder containing that file (use pwd and ls from Day 3 to be sure):
node values.js
Hello from Node
Read that line character by character. console is a built-in object Node gives you. The dot
means "reach inside it". log is the function that prints. The parentheses ( ) mean call this
now, and what sits inside them is the value you hand it. The quotes mark where the text starts
and stops. The semicolon ; ends the statement. Everything after // on a line is a comment
— ignored by JavaScript, written for humans.
Values and types
A value is a single piece of data. Every value has a type: the category JavaScript sorts it into. Three types carry almost all of your work.
A string is text, written between quotes — "Resistor 10k" or 'Resistor 10k'. The quotes
are not part of the value; they are the fence marking where the text starts and stops.
A number is numeric, written with no quotes: 10000, 0.05, -3. JavaScript has one number
type — whole numbers and decimals are both just number.
A boolean is one of exactly two values: true or false. No quotes. It answers a yes/no
question: "is this part in stock?"
Types are units on a measurement
A reading of 5 is meaningless until you say 5 volts or 5 ohms. The type is the unit: it
tells you which operations make sense. Adding volts to volts is fine; adding volts to a part
number is a mistake even though both look like numbers. JavaScript will not stop you, so the
discipline has to be yours.
Asking what type something is
The typeof operator takes one value and gives back a string naming its type.
console.log(typeof "Resistor 10k");
console.log(typeof 10000);
console.log(typeof true);
string
number
boolean
typeof is your multimeter for data. When a program misbehaves, printing typeof on the
suspicious value is often the fastest route to the cause.
Two kinds of nothing
JavaScript has two values that both mean "no value", and they differ in who decided.
null is intentional emptiness — you set it, on purpose, to say "deliberately blank". A
component that has not been discontinued has a discontinued date of null.
undefined is accidental emptiness: what you get when a variable exists but was never given
a value. Nobody assigned it; there is simply nothing there.
let discontinuedDate = null;
let supplier;
console.log(discontinuedDate, typeof discontinuedDate);
console.log(supplier, typeof supplier);
null object
undefined undefined
`typeof null` says `object` and that is wrong
A genuine bug from JavaScript's first version in 1995, kept forever because fixing it would
break existing websites. null is not an object. Memorise the exception; do not try to reason
your way to it.
The blank field and the missing form
null is a form where someone wrote "N/A" in the box — a deliberate answer. undefined is a
form nobody filled in. Both boxes look empty; only one was a decision.
Naming values: const and let
A variable is a name attached to a value, so you can refer to it later.
const resistanceOhms = 10000;
let stockCount = 42;
const and let are declarations — they create the name. The = is assignment: it puts
the value on the right into the name on the left. It does not mean "equals" in the maths sense.
The difference between them is whether the name can be pointed at a new value afterwards.
let allows reassignment:
let stockCount = 42;
stockCount = 40;
console.log(stockCount);
40
const forbids it. Trying to reassign stops the program:
const resistanceOhms = 10000;
resistanceOhms = 22000;
TypeError: Assignment to constant variable.
Use const by default. Reach for let only when the value must change. A const tells any
future reader "this will not move", which is one less thing to track. (You may see var in older
code. It is the pre-2015 declaration with confusing rules — do not use it.)
Names should say what the value is, including its unit: resistanceOhms, not r. JavaScript
convention is camelCase — lowercase first word, each later word capitalised.
Constants and test points
A const is a reference voltage: laid down once, relied on everywhere, and anything changing it
is a fault. A let is a live test point whose reading is expected to move. Choosing between
them is labelling which is which on your schematic.
Template literals
To build a sentence out of values, use a template literal: backticks ` instead of
quotes, with ${ } around each value to drop in.
const componentName = "Resistor 10k";
let stockCount = 42;
console.log(`${componentName} has ${stockCount} units left.`);
Resistor 10k has 42 units left.
console.log also accepts several values separated by commas, printing them space-separated.
Walkthrough
Create inventory.js and build it up a piece at a time, running after each addition.
const componentName = "Resistor 10k";
const resistanceOhms = 10000;
const tolerancePercent = 0.05;
let stockCount = 42;
let inStock = true;
console.log(`${componentName} — ${resistanceOhms} ohms`);
console.log("stockCount type:", typeof stockCount);
console.log("inStock type:", typeof inStock);
Run it with node inventory.js:
Resistor 10k — 10000 ohms
stockCount type: number
inStock type: boolean
Now sell two units by reassigning, and print again:
stockCount = 40;
console.log(`After sale: ${stockCount} units`);
After sale: 40 units
Checkpoint
Say why stockCount is let and resistanceOhms is const, and predict typeof tolerancePercent before running it. (It is number — 0.05 is a number though not whole.)
Your turn
Today's deliverable: a script whose variables use sensible names and const by default.
- In your
fullstack-journeyfolder, createjs-basics/day-15.js. - Declare five variables describing one real component: name (string), resistance in ohms
(number), tolerance percent (number), stock count (number), availability (boolean). Use
constfor everything that will not change;letonly for stock count. - Add
discontinuedDateset tonull, andsupplierdeclared withletand no value at all. console.logeach value, thenconsole.logthetypeofeach value. Runnode js-basics/day-15.jsafter every few lines.- Print a summary line using a template literal that reads like a sentence.
- Reassign
stockCountlower and print the summary again. - Deliberately try to reassign one
const. Read theTypeError, then delete the line. Breaking it on purpose is how you learn to recognise it later.
Tutor mode — after you have written step 4 yourself
"Quiz me on JavaScript primitive values. Give examples from electronics inventory data." A tutor-style request asks the AI to explain the concept, give a small example, then let you attempt it — never to hand you the finished file. Answer from memory before checking.
Common pitfalls
- Quoting numbers.
const stockCount = "42";makes a string.typeofsaysstring, and arithmetic will misbehave tomorrow. Numbers get no quotes. - Running from the wrong folder.
node day-15.jsfails withCannot find moduleif you are not where the file is. Runpwdfirst. - Missing a quote or backtick. You get
SyntaxError: Invalid or unexpected token. Every opener needs a partner. - Using
leteverywhere out of habit. It works, but throws away information. Default toconst; downgrade only when reassignment is genuinely needed.
Verify it yourself
Open today's reference, MDN's Dynamic scripting with JavaScript, and find its pages on variables and on data types.
- This lesson named five types: string, number, boolean, null, undefined. MDN lists at least two more primitive types. Find one and write down what it is for.
- Find MDN's own statement about
typeof null. Does it agree the result is a historical bug?
Add both answers as comments at the bottom of day-15.js. Correcting a simplified lesson with
something you found yourself is the habit that makes documentation useful.
The hour
- 0–5 min Recall
- 5–20 min Learn
Read only the listed concept notes and official reference sections needed today.
- 20–48 min Build
Write a script containing component name, resistance, tolerance, stock count, and availability. Log values and typeof results.
- 48–55 min Explain and verify
Run the result, inspect evidence, and explain the data/control flow in your own words.
- 55–60 min Quiz and commit
Complete the quiz, record one lesson, and commit the verified change when applicable.
What to hand in
A script whose variables use sensible names and const by default.
Working with AI today
Ask for explanations, analogies, questions, and hints. Do not request a complete finished solution first.
Quiz me on JavaScript primitive values. Give examples from electronics inventory data.
References
End-of-day quiz
Explain-back gate
Pass the quiz above to unlock completion.
Quiz + explain-back checks required.