The data type in JS
1. Numeric (number): Includes integers, floating-point numbers.
2. Boolean Type (Boolean)
3. String type
4. Objects (object)
5. Arrays (Array)
6. Null value (NULL)
7. Undefined (Undefined)
Two
1. Numeric type (number)
The more common methods of judging are:
function Isnumber (val) {
Return typeof val = = = ' number ';
}
2. Judging the variable Val is not a Boolean type
Function Isbooleantype (val) {
Return typeof val = = = "Boolean";
}
3. Determine if a variable is a string type
Function Isstringtype (val) {
Return typeof val = = = "string";
}
4. Determine if the variable is undefined
Function Isundefined (val) {
Return typeof val = = = "undefined";
}
5. Determine if the variable is not an object
function Isobj (str) {
if (str = = = NULL | | typeof str = = = ' undefined ') {
return false;
}
return typeof str = = = ' object ';
}
6. Determine if the variable is not NULL
Function IsNull (val) {
return val = = = NULL;
}
7. Determine if the variable arr is an array
Method One
function IsArray (arr) {
return Object.prototype.toString.apply (arr) = = = ' [Object Array] ';
}
Method Two
function IsArray (arr) {
if (arr = = = NULL | | typeof arr = = = ' undefined ') {
return false;
}
return Arr.constructor = = = Array;
}
JavaScript judgment variable data type