1. 程式人生 > >js typeof()返回的型別

js typeof()返回的型別

typeof的返回值共有七種:

number, boolean, string, undefined, object, function,symbol.

1、number

typeof(10);
typeof(NaN);
//NaN在JavaScript中代表的是特殊非數字值,它本身是一個數字型別。
typeof(Infinity);

2、boolean

typeof(true);
typeof(false);

3、string

typeof("abc");

4、undefined

typeof(undefined);
typeof(a);//不存在的變數

5、object

物件,陣列,null返回object
typeof(null);
typeof(window);

6、function

typeof(Array);
typeof(Date);

7、symbol

typeof Symbol() // ES6提供的新的型別