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. 翻页bug 在接口文档中应规范参数的取值区间 接口规范

    <?php$a=array("red","green","blue","yellow","brown&q ...

  2. vim 查找并替换多个匹配字符

    通常我们在使用vim的使用需要查找文档中是否含有需要的字符 1.vim 1.txt进入文档编辑 2.输入/键,再输入需要查找的字符,或者输入?键再输入需要查找的字符 3.查找到后可以enter进去,再 ...

  3. STM32 定时器详细篇(基于HAL库)

    l  16位的向上.向下.向上/向下(中心对齐)计数模式,支持自动重装载 l  16位的预分频器 l  每个定时器都有多个独立通道,每个通道可用于 *  输入捕获 *  输出比较 *  PWM输出 * ...

  4. Vue3(三)CND + ES6的import + 工程化的目录结构 = 啥?

    突发奇想 这几天整理了一下vue的几种使用方式,对比之后发现有很多相似之处,那么是不是可以混合使用呢?比如这样: vue的全家桶和UI库,采用传统的方式加载(CND.script). 自己写的js代码 ...

  5. 二:整合Spring Security

    整合Spring Security 1.项目创建 2.初次体验 3.用户名配置 3.1 配置文件配置用户名/密码 3.2 Java 配置用户名/密码 4.登录配置 5.忽略拦截 江南一点雨:Sprin ...

  6. SpringCloud配置中心实战

    SpringCloud配置中心实战 1.统一配置中心(Config) 1.1 Spring项目配置加载顺序 1.2 配置规则详解 1.3 Git仓库配置 1.3.1 使用占位符 1.3.2 模式匹配 ...

  7. Ajax原理,技术封装与完整示例代码

    在做项目和学习的时候,经常用到Ajax的相关技术,但是这方面的技术总是运用的不是十分好,就寻找相关博客来学习加深Ajax技术相关. 一.Ajax简介 二.同步.异步传输区别 2.1 异步传输 2.2 ...

  8. 函数式编程(json、pickle、shelve)

    本节内容 前言 json模块 pickle模块 shelve模块 总结 一.前言 1. 现实需求 每种编程语言都有各自的数据类型,其中面向对象的编程语言还允许开发者自定义数据类型(如:自定义类),Py ...

  9. Rsync同步工具

    1.Rsync介绍 1.1 什么是Rsync? Rsync,remote synchronize顾名思意就知道它是一款实现远程同步功能的软件,它在同步文件的同时,可以保持原来文件的权限.时间.软硬链接 ...

  10. Spring MVC 处理一个请求的流程分析

    Spring MVC是Spring系列框架中使用频率最高的部分.不管是Spring Boot还是传统的Spring项目,只要是Web项目都会使用到Spring MVC部分.因此程序员一定要熟练掌握MV ...