Home > Article > Web Front-end > How many data types are there in JavaScript? You will know after reading this
The content of this article is about the several types of JavaScript data. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
There are 7 JavaScript data types:
Undefined
Null
Boolean
String
Symbol
Number
Object
The 6 types except Object are primitive data types. Sometimes, we also subdivide the types of Object, such as Array, Function, Date, RegExp, etc.
typeof
typeof can be used to distinguish primitive data types except Null type. Object types can identify functions from ordinary objects:
Question 1: typeof cannot Identify null, how to identify null?
Answer: If you want to determine whether it is null, you can directly use the === congruence operator to determine (or use the Object.prototype.toString method below):
Question 2: Will typeof report an error if it acts on undefined variables?
Answer: No error will be reported, and "undefined" will be returned.
Question 3: What is the return value of typeof Number(1)?
Answer: "number". Note that when Number and String are called as ordinary functions, the parameters are converted into the corresponding primitive data types, which is similar to a forced type conversion operation, instead of being called as constructors by default. Note that to differentiate from Array, Array(...) is equivalent to new Array(...).
Question 4: What is the return value of typeof new Number(1)?
Answer: "object".
The above is a complete introduction to several JavaScript data types. If you want to know more about JavaScript video tutorials, please pay attention to the PHP Chinese website.
The above is the detailed content of How many data types are there in JavaScript? You will know after reading this. For more information, please follow other related articles on the PHP Chinese website!