更新時(shí)間:2022-10-09 10:49:38 來(lái)源:動(dòng)力節(jié)點(diǎn) 瀏覽1634次
簡(jiǎn)單數(shù)據(jù)類(lèi)型:Number、String、Boolean、Null、Undefined、Symbol(ECMAScript 2015 新增)、BigInt(ECMAScript 2020 新增)
復(fù)雜數(shù)據(jù)類(lèi)型:Arry、Object、Function
注意:需要確定某些數(shù)據(jù)類(lèi)型不推薦使用'==',推薦使用'==='。
以下打印結(jié)果為真
// Number type
var num = 12;
console.log(typeof num === 'number');
// console.log(num instanceof Number);// Can't judge
//String type
var str = "fgbb";
console.log(typeof str === 'string');
// console.log(str instanceof String);// Can't judge
//Boolean type
var tag = true;
console.log(typeof tag === 'boolean');
//Null
var nu = null;
console.log(typeof nu === 'object');
//Undefined
var un;
console.log(typeof un === 'undefined');
//Symbol
//Symbol Function stack cannot be used new command , because Symbol Is the original data type , Not object . You can take a string as an argument , For the newly created Symbol Provide a description , Used to display on the console or as a string , Easy to distinguish .
var sym = Symbol("sym");
sym = "any"
console.log(typeof sym === 'symbol');
//BigInt
var big = 12345n;
console.log(typeof big === 'bigint');
// Arry
var arr = [1,2,3,4,5,6];
// Object
var obj = {
name: "Bob",
age: 18
}
// Function
function fn(){
}
// instanceof
console.log(obj instanceof Object);
console.log(arr instanceof Array);
// __proto__
console.log(arr.__proto__ === Array.prototype);
console.log(obj.__proto__ === Object.prototype);
console.log(fn.__proto__ === Function.prototype);
console.log(Array.prototype.isPrototypeOf(arr));
console.log(Object.prototype.isPrototypeOf(obj));
console.log(Function.prototype.isPrototypeOf(fn));
console.log(Object.getPrototypeOf(arr) === Array.prototype);
console.log(Object.getPrototypeOf(obj) === Object.prototype);
// console.log(Function.getPrototypeOf(fn) === Function.prototype);// It is impossible to judge whether it is a function
// constructor
console.log(arr.constructor === Array);
console.log(obj.constructor === Object);
console.log(fn.constructor === Function);
// es6 New method of judging array
console.log(Array.isArray(arr));
相關(guān)閱讀
0基礎(chǔ) 0學(xué)費(fèi) 15天面授
有基礎(chǔ) 直達(dá)就業(yè)
業(yè)余時(shí)間 高薪轉(zhuǎn)行
工作1~3年,加薪神器
工作3~5年,晉升架構(gòu)
提交申請(qǐng)后,顧問(wèn)老師會(huì)電話(huà)與您溝通安排學(xué)習(xí)