Types
Explore JavaScript's fundamental data types including string, number, boolean, object, function, null, and undefined. Understand how to use the typeof operator, how primitive values can behave like objects through wrappers, and gain practical insight into JavaScript's type system to confidently handle variables and values in your code.
Values and variables always have a concrete type that you can access with the typeof operator, as shown is this sample:
JavaScript has only seven types by means of the value domain of the typeof operator. They are:
- object
- function
- string
- number
- boolean
- null
- undefined
⥴ The value of string, number, or boolean types are retrieved by typeof, respectively.
⥴ If the value is an object, or null (this value represents an empty object pointer), typeof returns object.
As you already learned, functions are first class citizens in JavaScript, so typeof retrieves function if you apply it on a function definition, as shown in this code snippet:
The undefined type has only one special value, undefined. When a variable is declared but not initialized, or you refer to a non-existing property ...