Console Learner — An interactive JavaScript course.
1.1 Primitive Types
The JavaScript language defines these primitive data types:
undefined – Used when a value is
missing. Stored in the undefined constant.
null – Used when a value is blank or empty.
Stored in the null constant.
boolean – Used for logical values.
Stored in the true & false constants.
number – Used for most numeric values.
Stored as floating-point 64-bit IEEE 754.
bigint – Used for large integer values.
Added in ES11 (2020) and not covered here.
string – Used for text values. Stored as
UTF-16 encoded (16 bit Unicode) values.
symbol – Used for guaranteed unique values.
Added in ES6 (2015) and not covered here.
object – Used for everything else.
More details on the next page.
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:
<Enter> — Execute the code
<Shift + Enter> — Add
line break
<Arrow-Up> — Previous
command in history
<Arrow-Down> — Next command in history
A special logging function is also available:
print(value) — Prints a value to
the console.
print(value, true) — Prints a debug
version of a value.
Need more magic? Check out the other
developer tools
on this site.