Always declare variables with a var statement, because sometimes a missing var can cause a hard-to-find bug. Experiments at the command line are the only exception to this rule.
We can change an array or a ‘dictionary’. Immutable values are values that can’t be changed. We can’t change, for example, the third character in a string.
Strings literals are delimited by single or double quote marks, with special characters escaped. There’s no difference between the two forms (except in single quote you don’t have to escape double quote, and vice versa.) Generally, I prefer the single quote form as it’s less busy on the eye and slightly easier to type.
js> s = 'Hello world.' Hello world.
We can add two strings together to produce a third string.
js> r = "I'm me. " I'm me. js> r + s I'm me. Hello world.
There’s a built-in operator called ‘typeof’ that returns a string that, sort-of, gives the type of a value.
js> typeof(s) string
js> typeof s string
Here we see that typeof produces (returns) a string.
js> typeof typeof s string
js> i = 42 42 js> typeof i number
js> t = true true js> typeof b boolean
Logical comparisions also produce Booleans.
js> f = (1 > 2) false js> typeof f boolean
undefined and null¶
js> typeof undefined undefined js> typeof null object
js> s = 'Hello world.' Hello world. js> s.lang = 'en' en js> s.lang === undefined true