Types
JavaScript has seven different defined data-types:
boolean
: Binary data-type. Only valid values are true or false.null
: keyword that denotes a null value. This is not 0. It is the absence of valueundefined
: a data-type that has not been defined with a value.number
: a numerical data-type.string
: any combination of characters to be read as text.symbol
: used to make anonymous object properties.object
: a container which can hold multiple data-type values.
Examples of each
boolean
null
undefined
number
string
symbol
Object
Dynamically-typed
JavaScript is a dynamically-typed language, meaning that variables aren't assigned a specific type. You can see this in action with the following example:
A single variable can be assigned multiple types, but only one type at any given time. Each time a value is assigned, it replaces the previous value.
File Location
Practice
In
types.js
, create a variable for each type and print each to the console.Create a new variable. Use the
typeof
keyword to print to the console:console.log(typeof x)
Change the value of that variable to a different data-type, then use
typeof
again.What happens? How can this be utilized in a program?
Last updated