Data types
- JavaScript is a dynamically typed language, meaning that there exist data types, but variables are not bound to any of them.
// no error let message = "hello"; message = 123456;
-
Number
- The number type represents both integer and floating point numbers.
- Besides regular numbers, there are so-called “special numeric values” which also belong to this data type:
Infinity
,-Infinity
andNaN
.
-
BigInt
- A
BigInt
value is created by appendingn
to the end of an integer.// the "n" at the end means it's a BigInt const bigInt = 1234567890123456789012345678901234567890n;
- A
-
String
- A string in JavaScript must be surrounded by quotes.
let str = "Hello";
- More in Fundamentals Part 2.
- A string in JavaScript must be surrounded by quotes.
-
Boolean
- This type is commonly used to store yes/no values:
true
means “yes, correct”, andfalse
means “no, incorrect”.
- This type is commonly used to store yes/no values:
-
The 'null' value
- It’s a special value which represents “nothing”, “empty” or “value unknown”.
- It forms a separate type of its own which contains only the
null
value:let age = null;
-
The “undefined” value
- The meaning of
undefined
is “value is not assigned”. - It makes a type of its own, just like
null
:let age; alert(age); // shows "undefined"
- The meaning of
-
Objects and Symbols
objects
are used to store collections of data and more complex entities.- The
symbol
type is used to create unique identifiers for objects.
-
The typeof operator
- The
typeof
operator returns the type of the operand. - Usually used as
typeof x
, buttypeof(x)
is also possible.
- The