Home >Web Front-end >Front-end Q&A >What are the data types returned by typeof?
The data types that "typeof" can return are: "number", "string", "boolean", "undefined", "object", and "function". Typeof is an operator, the syntax is "typeof (expression)", it performs operations on expressions.
The data types that "typeof" can return are: "number", "string", "boolean", "undefined", "object" , "function".
typeof is an operator. There are two ways to use it: typeof (expression) and typeof variable name. The first is to operate on expressions, and the second is to operate on variables. Do calculations.
1. If it is a basic data type, return the corresponding basic type
1.number type
var num = 1; console.log(typeof num);//返回的是number
2.string type
var str = 'jack'; console.log(typeof str);//返回的是string
3. boolean type
var boo =true; console.log(typeof boo);//返回的是boolean
4.undefined type
var und ; console.log(typeof und);//返回的是undefined
2. If it is a complex data type
1. Array type
var arr = new Array(); console.log(typeof arr); //返回的是object // 2.function类型 var fn = function(){}; console.log(typeof fn); //返回的是function
3.Object type
var obj = new Object(); var nul =null;(特别地) console.log(typeof nul); //返回的是object console.log(typeof obj); //返回的是object
4.Literal array
var arr2 = [1,32]; console.log(typeof arr2);//返回的是object
5.Customized object
function Person(name){ this.name =name; } var stu = new Person(); console.log(typeof stu); //返回的是object // 可以得出:复杂数据类型,如果是对象,则返回的是object,如果的function类型,则返回的是function // 所以:typeof 可以返回的类型为:number、string、boolean、undefined、object、function
For more related knowledge, please visitPHP中文网! !
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!