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. 一套高可用、易伸缩、高并发的IM群聊、单聊架构方案设计实践

    一套高可用.易伸缩.高并发的IM群聊.单聊架构方案设计实践 一套高可用.易伸缩.高并发的IM群聊.单聊架构方案设计实践-IM开发/专项技术区 - 即时通讯开发者社区! http://www.52im. ...

  2. openrstry 限流 是否有清零逻辑 连接池

    openrstry  限流  是否有清零逻辑 https://github.com/openresty/lua-resty-limit-traffic # encoding=utf-8 # Shawn ...

  3. 前序遍历 排序 二叉搜索树 递归函数的数学定义 return 递归函数不能定义为内联函数 f(x0)由f(f(x0))决定

    遍历二叉树   traversing binary tree 线索二叉树 threaded binary tree 线索链表 线索化 1. 二叉树3个基本单元组成:根节点.左子树.右子树 以L.D.R ...

  4. 获取当前文件路径 import 原理 一般把模块组成的集合称为包(package)

    获取当前文件路径 testpath.py import sysprint(sys.path) [root@d mapReduceLog]# python testpath.py['/data/mapR ...

  5. 进程通信类型 管道是Linux支持的最初Unix IPC形式之一 命名管道 匿名管道

    管道 Linux环境进程间通信(一) https://www.ibm.com/developerworks/cn/linux/l-ipc/part1/index.html 管道及有名管道 郑彦兴200 ...

  6. Group by 优化

    一个标准的 Group by 语句包含排序.分组.聚合函数,比如 select a,count(*) from t group by a ;  这个语句默认使用 a 进行排序.如果 a 列没有索引,那 ...

  7. 八:SpringBoot-集成JPA持久层框架,简化数据库操作

    SpringBoot-集成JPA持久层框架,简化数据库操作 1.JPA框架简介 1.1 JPA与Hibernate的关系: 2.SpringBoot整合JPA Spring Data JPA概述: S ...

  8. python yield初探 (转)

    1. iterator叠代器最简单例子应该是数组下标了,且看下面的c++代码: int array[10]; for ( int i = 0; i < 10; i++ )    printf(& ...

  9. java解压zip压缩包

    package com.spring.mvc.zip; import java.io.File;import java.io.FileOutputStream;import java.io.Input ...

  10. python——模块、标准库、第三方模块安装

    模块(module)简介 模块化--指将一个完整的程序分解为一个一个小的模块,通过将模块组合,来搭建出一个完整的程序. 模块化的特点: ① 方便开发 ② 方便维护 ③ 模块可以复用! 在Python中 ...