1.What is the data type?
In most programming languages we are exposed to, data is classified, including numbers, characters, logic truth and false: int, long, string, boolean..., etc.; we all know that computers use binary methods to process data. Loading the data into memory and computed through CPU scheduling to get the final result. So, does the data type be recorded when storing data in memory? I think the answer is no. The data in memory should be distinguished and calculated based on the size of the memory occupied. For the CPU, the calculation of two different types of data is only scheduled for two data with different memory sizes to calculate, so for the CPU, the data is only 1 and 0. Then there is a problem here. Some people will say that some two types of data in Java language cannot be directly calculated and must be converted to calculate. Here, it is the difference between strong types and weak types. Strong type languages will strictly check each type of data, that is, check the space occupied by each type of memory. If the requirements do not meet the requirements, compilation or operation will not be allowed. Weak types do not strictly check the data, allowing most data types to be calculated directly, and JavaScript is a weak type.
2. What types of JavaScript are there?
Including the following types:
Number: that is, the number includes floating point numbers
Boolean: true or false
String: string
Null: an empty object pointer, indicating that the memory space pointed to does not exist
Undefined: Undefined, indicating that the memory space pointed to exists, but no data
Object: A complex data type in 1. If you are familiar with object-oriented languages similar to Java, you should understand it very well.
Through the above 6 types, the data can be classified. JavaScript is declared with the keyword var for the container of data. So how do you determine which type a variable is? This requires the keyword typeof
Here, it should be noted that typeof is an operator (similar to +, -, *, /) rather than function. You can use typeof a directly (although this is not recommended). null and undefined are equal when compared to size. Because undefined derives from null.
Below is an example of typeof
The code copy is as follows:
var message='some string';
var obj=new Object();
var a;
alert(typeof message);//'string'
alert(typeof(message));//'string'
alert(typeof(95));//'number'
alert(typeof(a));//'undefined'
alert(typeof(null==undefined));//'boolean'
alert(null==undefined);//'true'
alert(obj);//'object'
alert(null);//'object' (may also be 'null' in different browsers)
The above is all about javascript data types, I hope you like it.