Home >Web Front-end >JS Tutorial >A brief discussion on JavaScript data types_Basic knowledge
1. What is the data type?
Most of the programming languages we come into contact with classify data, including numbers, characters, logical truth and falsehood: int, long, string, boolean....etc.; we all know that computers classify data It is processed in binary format. The data is loaded into the memory and calculated through CPU scheduling to obtain the final result. Then, will the type of data be recorded when the memory stores the data? I think the answer is no. The data in the memory should be distinguished and calculated according to the size of the memory occupied. The calculation of two different types of data only schedules two different memory sizes for the CPU. Data is used to perform calculations, so for the CPU, the data is only 1 and 0. Then there is a problem here. Some people will say that certain two types of data in the Java language cannot be calculated directly and must be converted before calculation can be done. Here is the difference between strong typing and weak typing. Strongly typed languages will strictly check each type of data, that is, check the memory space occupied by each type. If it does not meet the requirements, it will not be allowed to compile or run. Weak typing does not strictly check the data and allows most data types to be calculated directly. JavaScript is weakly typed.
2. What are the types of JavaScript?
Including the following types:
Number: That is, numbers include floating point numbers
Boolean: true or false
String: string
Null: Null object pointer, indicating that the memory space pointed to does not exist
Undefined: Undefined, indicating that the memory space pointed to exists, but there is no data
Object: A complex data type. If you are familiar with object-oriented languages such as Java, you should have a good understanding of this
Through the above 6 types, data can be classified. For data containers, JavaScript uses the keyword var to declare. So how to determine what type a variable is? This requires the keyword typeof
Here, it should be noted that typeof is an operator (similar to , -, *, /) rather than a function. You can use typeof a directly (although this is not recommended). And null and undefined are equal when comparing sizes. Because undefined is derived from null.
The following is an example of typeof
That’s all about JavaScript data types, I hope you like it.