js types & primitive & object
js 数据类型
typeof null
// "object"
typeof undefined
// "undefined"
typeof Symbol('symbol desc')
// "symbol"
typeof Symbol
// "function"
typeof `strings`
// "string"
typeof 123
// "number"
typeof NaN;
// "number"
typeof BigInt(1n);
// "bigint"
typeof true
// "boolean"
typeof function() {}
// "function"
typeof (() => {})
// "function"
typeof () => {}
// Uncaught SyntaxError: Malformed arrow function parameter list
typeof {}
// "object"
typeof []
// "object"
typeof NaN
// "object"
NaN
Number.isNaN(NaN)
// true
isNaN(NaN)
// true
Number.isNaN('hello world');
// false
isNaN('hello world');
// true
Number.isNaN(``)
// false
Number.isNaN(0)
// false
isNaN(``)
// false
isNaN(0)
// false
NaN === NaN; // false
Number.NaN === NaN; // false
isNaN(NaN); // true
isNaN(Number.NaN); // true
Number.isNaN(NaN); // true
function valueIsNaN(v) { return v !== v; }
valueIsNaN(1); // false
valueIsNaN(NaN); // true
valueIsNaN(Number.NaN); // true
isNaN('hello world'); // true
Number.isNaN('hello world'); // false
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN
Array
Array.isArray([])
// true
Array.isArray({})
// false
null
const nl = null;
// null
nl === null
// true
typeof null // "object" (not "null" for legacy reasons)
typeof undefined // "undefined"
null === undefined // false
null == undefined // true
null === null // true
null == null // true
!null // true
isNaN(1 + null) // false
isNaN(1 + undefined) // true
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null
Symbol
typeof Symbol('symbol desc')
// "symbol"
typeof Symbol
// "function"
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
function
const obj = {};
const func = () => {};
obj instanceof Object;
// true
func instanceof Object;
// true
func instanceof Function;
// true
obj instanceof Function;
// false
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof
Object
Object.prototype.toString
Object.prototype.toString.apply(obj)
// "[object Object]"
Object.prototype.toString.apply(func)
// "[object Function]"
Object.prototype.toString.apply
Object.prototype.toString.apply(Symbol(`s desc`))
// "[object Symbol]"
Object.prototype.toString.apply(NaN)
// "[object Number]"
Object.prototype.toString.apply(123)
// "[object Number]"
Object.prototype.toString.apply(BigInt(1n))
// "[object BigInt]"
Object.prototype.toString.apply(null)
// "[object Null]"
Object.prototype.toString.apply(``)
// "[object String]"
Object.prototype.toString.apply(true)
// "[object Boolean]"
Object.prototype.toString.apply(undefined)
// "[object Undefined]"
Object.prototype.toString.call
Object.prototype.toString.call(NaN)
"[object Number]"
Object.prototype.toString.call(undefined)
"[object Undefined]"
Object.prototype.toString.call(true)
"[object Boolean]"
Object.prototype.toString.call({})
"[object Object]"
Object.prototype.toString.call(func)
"[object Function]"
Object.prototype.toString.call(obj)
"[object Object]"
Object.prototype.toString.call(Symbol())
"[object Symbol]"
Object.prototype.toString.call(null)
"[object Null]"
Object.prototype.toString.call(123)
"[object Number]"
Object.prototype.toString.call(BigInt(1n))
"[object BigInt]"
The latest ECMAScript standard defines 8 data types:
7 data types that are primitives:
Boolean
Null
Undefined
Number
BigInt (ES10 / 2019 新增)
String
Symbol (ES6 / ES2015 新增)
1 data type that is reference:
Object
function() {}
() => {}
typeof
'number'
'string'
'boolean'
'undefined'
'bigint'
'symbol'
'object'
'function'
refs
https://flaviocopes.com/difference-primitive-types-objects/
https://flaviocopes.com/javascript-value-type/
TypeScript types
types & primitive & object
http://javascript.xgqfrms.xyz/pdfs/TypeScript Language Specification.pdf
// const a: Object = [- 7 , 1, 5, 2, -5, 1];
// const b: Object = [2, 3, 4, 2, 4];
// const c: Object = [2, 3, 4, 3, 2];
// const a: Number[] = [- 7 , 1, 5, 2, -5, 1];
// const b: Number[] = [2, 3, 4, 2, 4];
// const c: Number[] = [2, 3, 4, 3, 2];
const a: number[] = [- 7 , 1, 5, 2, -5, 1];
const b: number[] = [2, 3, 4, 2, 4];
const c: number[] = [2, 3, 4, 3, 2];
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!