Summary
-
Dynamic typing, meaning that there exist data types, but variables are not bound to any of them. A union is a special data type available in programming language C that allows storing different data types in the same memory location and dynamic typing is often implemented using tagged union.
-
The
Number
type represents both integer and floating point numbers. Besides regular numbers, there are special numeric values likeInfinity
,-Infinity
, andNaN
. -
The
BigInt
type was recently added to the language to represent integers of arbitrary length. It is useful when we are doing stuff like cryptography or microsecond-precision timestamps. ABigInt
can be created by appendingn
to the end of an integer. -
A
String
type has to be surrounded by quotes. Double and single quotes are simple quotes while backticks are extended functionality quotes that allow variable and expression embedding using${...}
. -
The
Boolean
type has only two values,true
andfalse
. -
The
null
type is a special one represents unknown value. It is not a reference to a non-existing object or a null pointer. -
The
undefined
type means the variable is declared but not assigned. Technically it is possible to explicitly assignundefined
to a variable but it is note recommended. Normally, one usesnull
to assign an empty or unknown value to a variable, whileundefined
is reserved as a default initial value for unassigned things. -
The
Object
type is used to store collections of data and more complex entities compared with every other type which is primitive and stores only one single thing. -
The
Symbol
type is used to create unique identifiers for objects. -
The
typeof
operator returns the type of the operand. -
The result of
typeof Math
isobject
asMath
is a built-in object that provides mathematical operations. -
The result of
typeof null
isobject
. That’s an officially recognized error, coming from very early days of JavaScript and kept for compatibility. `null is a special value with a separate type of its own. -
The result of
typeof alert
isfunction
.function
belongs to the object type, so whattypeof
shows is incorrect, but can be convenient in practice. -
typeof(x)
is the same astypeof x
.typeof
is an operator, not a function. The parentheses here aren’t a part oftypeof
but a kind of mathematical grouping for expression.
Tasks
-
String quotes
let name = "Ilya" alert(`hello ${1}`) // hello 1 alert(`hello ${"name"}`) // hello name alert(`hello ${name}`) // hello Ilya