JavaScript – 驗證Variable類型

var a = 3;
console.log(typeof a);  //number

var b = "Hello";
console.log(typeof b);  //string

var c = {};
console.log(typeof c);  //object

var d = [];
console.log(typeof d);  //object
console.log(Object.prototype.toString.call(d));  //[object Array]

var e = false;
console.log(typeof e);  //boolean

function Person(name){ this.name = name; }
console.log(typeof Person);  //function

var f = new Person("Jane");
console.log(typeof f);  //object
console.log(typeof undefined);  //undefined
console.log(typeof null);  //object

開始在上面輸入您的搜索詞,然後按回車進行搜索。按ESC取消。

返回頂部