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?
363
16-Jul-2023
Updated on 17-Jul-2023
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
typeofoperator to determine the type of a variable. For example, the following code will print the type of the variablemyVar:The
typeofoperator 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:
typeofoperator