Common data types in JavaScript are divided into basic types (Number, String, Boolean, Null, Undefined) and complex types (Array, Object, Date, RegExp, Error). Use the typeof operator to determine the type of data, such as console.log(typeof 42) output "number".
Common data types in JavaScript
Data types in JavaScript refer to the storage and processing of different types Classification of variables in the data. The following are several common data types in JavaScript:
1. Basic data types
2. Complex data type
3. Special data types
How to determine the type of data
You can use the typeof
operator to determine the data type of a variable. For example:
<code class="js">console.log(typeof 42); // "number" console.log(typeof "hello world"); // "string" console.log(typeof true); // "boolean" console.log(typeof null); // "object" console.log(typeof undefined); // "undefined"</code>
It should be noted that although null
is a special value, it is treated as an object in JavaScript.
The above is the detailed content of Common data types in js. For more information, please follow other related articles on the PHP Chinese website!