Values come in different kinds, and programs go wrong when the kinds get mixed up by accident. Here you'll check what kind of value you are holding, convert deliberately between text and numbers, compare two values to get a true-or-false answer, and combine several of those answers into one condition.
Overview
Syllabus
Checking a Value's Kind with typeof
- Check a Number and a Piece of Text
- Check a Stored Value
- Text That Looks Like a Number
- Label All Three Types
Converting Between Text and Numbers
- See the Plus Sign Trap
- Convert Text to a Number
- Convert a Number to Text
- Repair a Wrong Total
Comparing Values with === and Other Operators
- Compare Two Numbers
- Store a Comparison
- Check Equality Strictly
- Write a Stock Report
Combining Conditions with &&, ||, and !
- Both Must Be True
- Either Will Do
- Flip an Answer
- Decide Whether the Shop Can Serve