Home > Web Front-end > Front-end Q&A > What are the data types returned by typeof?

What are the data types returned by typeof?

烟雨青岚
Release: 2020-07-03 14:38:39
Original
7738 people have browsed it

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.

What are the data types returned by typeof?

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
Copy after login

2.string type

        var str = 'jack';
        console.log(typeof str);//返回的是string
Copy after login

3. boolean type

    var boo =true;
        console.log(typeof boo);//返回的是boolean
Copy after login

4.undefined type

    var und ;
        console.log(typeof und);//返回的是undefined
Copy after login

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
Copy after login

3.Object type

        var  obj = new Object();
        var nul =null;(特别地)
        console.log(typeof nul); //返回的是object
        console.log(typeof obj); //返回的是object
Copy after login

4.Literal array

        var arr2 = [1,32];
        console.log(typeof arr2);//返回的是object
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template