Home >Web Front-end >JS Tutorial >What are the data types returned by typeof

What are the data types returned by typeof

青灯夜游
青灯夜游Original
2020-11-11 14:43:0717844browse

There are 6 data types returned by typeof, namely: 1. object, object type; 2. undefined, undefined type; 3. string, string type; 4. number, numeric type; 5. boolean, Boolean type; 6. function, function type.

What are the data types returned by typeof

typeof returns a total of 6 data formats:

1, object      —Variables or values ​​of object type, Or null (this is a problem left by JS history, treat null as the Object type)

2, UNDEFINED-Unfalted variables or values ​​

3, String-String-string type variables Or value

4、number --Numeric type variable or value

5、boolean --Boolean type variable or value

6、function --Function type Variable or value

Example:

Undefined

var a1; 
typeof(a1);

Run result:

What are the data types returned by typeof

number

var num1=12; 
typeof(num1);

Run result:

What are the data types returned by typeof

string

var num2="12"; 
typeof(num2);

Run result:

What are the data types returned by typeof

boolean

var flag=true; 
typeof(flag);

Run result:

What are the data types returned by typeof

object

var str=new String();
typeof(str);
var a=null; 
typeof(a);

Run result:

What are the data types returned by typeof

function

var fn = function(){};
typeof(fn); 
typeof(class c{});

Run result:

What are the data types returned by typeof

For more programming-related knowledge, please visit: Introduction to Programming! !

The above is the detailed content of What are the data types returned by typeof. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:what is react-domNext article:what is react-dom