更新時間:2022-10-09 10:49:38 來源:動力節點 瀏覽1419次
簡單數據類型:Number、String、Boolean、Null、Undefined、Symbol(ECMAScript 2015 新增)、BigInt(ECMAScript 2020 新增)
復雜數據類型:Arry、Object、Function
注意:需要確定某些數據類型不推薦使用'==',推薦使用'==='。
以下打印結果為真
// 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));
0基礎 0學費 15天面授
有基礎 直達就業
業余時間 高薪轉行
工作1~3年,加薪神器
工作3~5年,晉升架構
提交申請后,顧問老師會電話與您溝通安排學習