Console Learner — An interactive JavaScript course.


1.1 Primitive Types

The JavaScript language defines these primitive data types:

The undefined constant used to be a writable in legacy JavaScript (prior to ES5). Therefore, it is common for code to avoid it.
This is similar to a double in some other languages. Numbers being floating-point is a frequent cause for bugs. So never EVER rely on built-in numbers when performing monetary or precise calculations. Use a well-tested library instead.
Some Unicode characters can only be represented in UTF-16 by using a surrogate pair, i.e. two characters in sequence forming a single glyph on screen (e.g. emojis). JavaScript only provides limited helpers for handling this, all of which are modern additions.
>>>
Object.doesNotExist
undefined
>>>
null
null
>>>
true
true
>>>
4711.0
4711
>>>
1.5E-5
0.000015
>>>
42 / 9
4.666666666666667
>>>
0.1 + 0.2
0.30000000000000004
Ouch! As numbers are always floating-point, rounding-errors like this lurks behind every corner.
>>>
0 / 0
NaN
The special NaN (Not A Number) value is also frequently a cause for problems.
>>>
"a 'string'"
"a 'string'"
>>>
'another "string"'
"another \"string\""
There are two syntaxes for string literals (using " or ') and both have exactly the same meaning.
>>>
"\061, \x32, \u0033, \u{34}"
"1, 2, 3, 4"
Octal and hexadecimal character escapes are available.
>>>

The console allows you to interact with the course material and examples. Use the following keys:

A special logging function is also available:


Need more magic? Check out the other developer tools on this site.