- 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,Infinityand floating point rounding (0.1 + 0.2). - Booleans are
trueorfalse. undefinedmeans "not given a value yet."nullmeans "empty on purpose."typeoftells you a value's type (buttypeof nullis"object", a famous old bug).- Convert types on purpose with
Number(),parseInt(),parseFloat()andString(). - 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.