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 发布文章使用:只允许注册用户才可以访问!


js types & primitive & object的更多相关文章

  1. JS 深度拷贝 Object Array

    JS 深度拷贝 Object Array function cloneObj(o) { var isArray = o instanceof Array; var isObject = o insta ...

  2. JS如何遍历Object中的所有属性?

    JS如何遍历Object中的所有属性? var params = ""; for(var i in baseParams){ params += "&" ...

  3. js如何判断Object是否为空?(属性是否为空)

    js 判断一个 object 对象是否为空 转载原文 判断一个对象是否为空对象,本文给出三种判断方法: 1.最常见的思路,for...in... 遍历属性,为真则为“非空数组”:否则为“空数组” fo ...

  4. 聊一聊JS输出为[object,object]是怎么回事

    JS输出为[object object] 今天在学习ES6中的 Symbol 数据类型时,在写demo时控制台输出为 Symbol[object object] ,当时有点疑惑,查阅了相关资料后搞清楚 ...

  5. 聊一聊 JS 输出为 [object object] 是怎么回事?

    聊一聊 JS 输出为 [object object] 是怎么回事? 今天在学习ES6中的 Symbol 数据类型时,在写demo时控制台输出为 Symbol[object object] ,当时有点疑 ...

  6. JS json对象(Object)和字符串(String)互转方法

    [JS json对象(Object)和字符串(String)互转方法] 参考:https://blog.csdn.net/wenqianla2550/article/details/78232706 ...

  7. js & h5 & app & object storage

    js & h5 & app & object storage API https://developer.mozilla.org/en-US/docs/Web/API Stor ...

  8. js & sort array object

    js & sort array object sort array object in js https://flaviocopes.com/how-to-sort-array-of-obje ...

  9. js in depth: Object & Function & prototype & __proto__ & constructor & classes inherit

    js in depth: Object & Function & prototype & proto & constructor & classes inher ...

随机推荐

  1. P5858 Golden Swold

    写在前面 简单的单调队列优化 DP 处理略微有点恶心,于是乎,用来取 \(\max\) 的极小值直接开到了 long long 的最小极限,了 define int long long /cy 算法思 ...

  2. LOJ10162 骑士

    ZJOI 2008 Z 国的骑士团是一个很有势力的组织,帮会中聚集了来自各地的精英.他们劫富济贫,惩恶扬善,受到了社会各界的赞扬. 可是,最近发生了一件很可怕的事情:邪恶的 Y 国发起了一场针对 Z ...

  3. 一:Spring Boot 的配置文件 application.properties

    Spring Boot 的配置文件 application.properties 1.位置问题 2.普通的属性注入 3.类型安全的属性注入 1.位置问题 当我们创建一个 Spring Boot 工程时 ...

  4. JDBC连接数据库,数据库访问层

    为什么需要JDBC JDBC API DriverManager JDBC驱动 JDBC的功能 JDBC步骤 数据访问层DAO DAO模式的组成 DAO模式的实际应用 为什么需要JDBC? JDBC是 ...

  5. Phoenix表和索引分区优化方法

    Phoenix表和索引分区,基本优化方法 优化方法 1. SALT_BUCKETS RowKey SALT_BUCKETS 分区 2. Pre-split RowKey分区 3. 分列族 4. 使用压 ...

  6. MySQL 数据库性能调优

    MySQL 数据库性能调优 MySQL性能 最大数据量 最大并发数 优化的范围有哪些 存储.主机和操作系统方面: 应用程序方面: 数据库优化方面: 优化维度 数据库优化维度有四个: 优化选择: 数据库 ...

  7. scp命令------两服务器之间传输数据

    scp就是secure copy,是用来进行远程文件拷贝的.数据传输使用 ssh,并且和ssh 使用相同的认证方式,提供相同的安全保证 . 与rcp 不同的是,scp 在需要进行验证时会要求你输入密码 ...

  8. P1046 陶陶摘苹果 Python实现

    题目描述 陶陶家的院子里有一棵苹果树,每到秋天树上就会结出1010个苹果.苹果成熟的时候,陶陶就会跑去摘苹果.陶陶有个3030厘米高的板凳,当她不能直接用手摘到苹果的时候,就会踩到板凳上再试试. 现在 ...

  9. Linux常用命令:性能命令

    本文介绍Linux常用性能统计分析命令,监控进程或者系统性能.主要包括CPU(top.mpstat).内存(vmstat.free).I/O(iostat).网络性能(sar).系统日志信息(dems ...

  10. Codeforces Round #589 (Div. 2) D. Complete Tripartite(模拟)

    题意:给你n个点 和 m条边 问是否可以分成三个集合 使得任意两个集合之间的任意两个点都有边 思路:对于其中一个集合v1 我们考虑其中的点1 假设点u和1无边 那么我们可以得到 u一定和点1在一个集合 ...