typeof操作符的返回值

2022-06-16 21:15:08 字數 421 閱讀 2456

對乙個值使用typeof操作符可能返回下列某個字串:

1):undefined——如果這個值未定義

2):boolean——如果這個值是布林值

3):string——如果這個值是字串

4):number——如果這個值是數值

5):object——如果這個值是物件或null,陣列,物件(如)等,用typeof來檢測,那麼返回值就是object

6):function——如果這個值是函式

判斷乙個js物件是否為陣列的方法,使用instanceof 如果返回值是 array,那麼就是js陣列。

例子:var a = new array();

a.push('abc');

a.push(2234);

var flag =a instanceof array;//true

typeof與instanceof操作符

typeof與instanceof都是用來檢測變數型別的,不同的是,typeof用來檢測基本資料型別,instanceof用來檢測引用型別 一 typeof操作符 typeof操作符是確定乙個變數是字串 數值 布林值 還是undefined的最佳工具 對乙個值使用typeof操作符可能返回下列某個字...

js中的typeof 操作符

使用postman進行介面測試,其中驗證欄位的型別用到了typeof 驗證型別 tests code type is number typeof responsejson.code number tests items type is object typeof responsejson.items...

常見typeof返回值(P0)

numbers typeof 37 number typeof 3.14 number typeof math.ln2 number typeof infinity number typeof nan number 儘管nan是 not a number 的縮寫 typeof number 1 nu...