Recap

Grade 2, page 13 of 13. A one-minute read.

  • Every value has a type. The main ones are string, number, boolean, undefined, null, and object.
  • Strings are text in quotes: 'single', "double", or `backticks`. Use \ to escape special characters like \n (new line).
  • Template literals (backticks) let you insert values with ${ } and can span multiple lines.
  • Strings have a length, and each character has an index that starts at 0.
  • Useful string methods: toUpperCase, toLowerCase, trim, includes, startsWith, endsWith, indexOf, slice, replace, repeat, padStart, at.
  • String methods return new strings. The original never changes.
  • Numbers can be whole or decimal. Watch out for NaN, Infinity and floating point rounding (0.1 + 0.2).
  • Booleans are true or false.
  • undefined means "not given a value yet." null means "empty on purpose."
  • typeof tells you a value's type (but typeof null is "object", a famous old bug).
  • Convert types on purpose with Number(), parseInt(), parseFloat() and String().
  • Type coercion: + with a string glues; other math operators convert to numbers. Don't rely on it!

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