Data Types: What Goes in the Boxes?

Text, numbers, true and false, and two different kinds of nothing. Thirteen short pages from Grade 2 of Elementary School, about 17 minutes of reading in all.

What you’ll learn

  • The different types of values in JavaScript
  • Strings, quotes and escape characters
  • Template literals (the easy way to build text)
  • String methods like toUpperCase and includes
  • Numbers, decimals, and the weird ones: NaN and Infinity
  • Why 0.1 + 0.2 isn't exactly 0.3
  • Booleans, undefined and null
  • Converting between types (and JavaScript's surprise conversions)

The pages

Thirteen pages, about 17 minutes.

  1. The Kinds of Things in the Boxes In Grade 1, we put all sorts of things into our variable boxes: names, ages, prices. You might have noticed that some…
  2. Strings: Text in Quotes A string is a piece of text. It's called a "string" because it's a string of characters, one after another, like beads…
  3. Template Literals: The Easy Way to Build Strings In Grade 1, we built messages by gluing strings and variables together with +. It works, but all those + signs and…
  4. String Superpowers Strings come with a whole toolbox of built-in abilities. Let's look at the most useful ones. Every string knows its…
  5. Numbers The number type holds, well, numbers. Unlike some other languages, JavaScript doesn't care whether a number is whole…
  6. The Weird Numbers: NaN, Infinity and 0.1 + 0.2 Numbers are mostly well-behaved. But they have a few oddball relatives that show up at family gatherings and make…
  7. Booleans: True or False A boolean is the simplest type of all. It has only two possible values: true and false. That's it. Yes or no. On or…
  8. undefined and null: Two Kinds of Nothing JavaScript has not one, but two different values that mean "nothing." This confuses people, so let's clear it up…
  9. typeof: What's in the Box? Sometimes you want to know what type of value a variable is holding. JavaScript has a handy operator for that called…
  10. Type Conversion: Changing Types on Purpose Sometimes you have a value of one type, but you need it to be another type. The classic example is prompt, which…
  11. Type Coercion: JavaScript's Surprise Gifts When you mix different types in an operation, JavaScript doesn't throw an error. Instead, it quietly converts one of…
  12. Mini Project: The Message Analyzer Let's use our new string superpowers to build a little tool that analyzes a text message. Grade 2, done! You now know…
  13. Recap The key ideas of Grade 2, JavaScript data types, on one page. Every value has a type. The main ones are string…

Reading is step one

CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.

Start learning