What are the different data types in JavaScript and how to determine the type of a variable?
What are the different data types in JavaScript and how to determine the type of a variable?
15716-Jul-2023
Updated on 17-Jul-2023
Home / DeveloperSection / Forums / What are the different data types in JavaScript and how to determine the type of a variable?
What are the different data types in JavaScript and how to determine the type of a variable?
Aryan Kumar
17-Jul-2023JavaScript has seven primitive data types:
In addition to these primitive data types, JavaScript also has objects, which are complex data structures that can contain any combination of primitive and object types.
The type of a variable is determined by the value that is assigned to it. For example, if you assign the string "Hello, world!" to a variable, the type of the variable will be "string".
You can use the
typeof
operator to determine the type of a variable. For example, the following code will print the type of the variablemyVar
:The
typeof
operator can also be used to determine the type of an object. For example, the following code will print the type of the objectmyObject
:Here is a table that summarizes the different data types in JavaScript and how to determine their type:
typeof
operator