js types & primitive & object
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的更多相关文章
- JS 深度拷贝 Object Array
JS 深度拷贝 Object Array function cloneObj(o) { var isArray = o instanceof Array; var isObject = o insta ...
- JS如何遍历Object中的所有属性?
JS如何遍历Object中的所有属性? var params = ""; for(var i in baseParams){ params += "&" ...
- js如何判断Object是否为空?(属性是否为空)
js 判断一个 object 对象是否为空 转载原文 判断一个对象是否为空对象,本文给出三种判断方法: 1.最常见的思路,for...in... 遍历属性,为真则为“非空数组”:否则为“空数组” fo ...
- 聊一聊JS输出为[object,object]是怎么回事
JS输出为[object object] 今天在学习ES6中的 Symbol 数据类型时,在写demo时控制台输出为 Symbol[object object] ,当时有点疑惑,查阅了相关资料后搞清楚 ...
- 聊一聊 JS 输出为 [object object] 是怎么回事?
聊一聊 JS 输出为 [object object] 是怎么回事? 今天在学习ES6中的 Symbol 数据类型时,在写demo时控制台输出为 Symbol[object object] ,当时有点疑 ...
- JS json对象(Object)和字符串(String)互转方法
[JS json对象(Object)和字符串(String)互转方法] 参考:https://blog.csdn.net/wenqianla2550/article/details/78232706 ...
- js & h5 & app & object storage
js & h5 & app & object storage API https://developer.mozilla.org/en-US/docs/Web/API Stor ...
- js & sort array object
js & sort array object sort array object in js https://flaviocopes.com/how-to-sort-array-of-obje ...
- js in depth: Object & Function & prototype & __proto__ & constructor & classes inherit
js in depth: Object & Function & prototype & proto & constructor & classes inher ...
随机推荐
- 请你尽量全面的说一个对象在 JVM 内存中的结构?
从 Java 14 开始,Project Valhala引入了 Value Type(或者称为 inline type),参考: Valhalla: https://openjdk.java.net/ ...
- synchronized的底层探索
其实没看懂,但是提供了不同的思路,先记下 https://www.cnblogs.com/yuhangwang/p/11256476.html https://www.cnblogs.com/yuha ...
- Java IO--字节流与字符流OutputStream/InputStream/Writer/Reader
流的概念 程序中的输入输出都是以流的形式保存的,流中保存的实际上全都是字节文件. 字节流与字符流 内容操作就四个类:OutputStream.InputStream.Writer.Reader 字节流 ...
- Spark练习之创建RDD(集合、本地文件),RDD持久化及RDD持久化策略
Spark练习之创建RDD(集合.本地文件) 一.创建RDD 二.并行化集合创建RDD 2.1 Java并行创建RDD--计算1-10的累加和 2.2 Scala并行创建RDD--计算1-10的累加和 ...
- hadoop的hdfs中的namenode和datanode知识总结
一,NameNode: 1, Namenode是中心服务器,单一节点(简化系统的设计和实现),负责管理文件系统的名称空间(namespace)以及客户端对文件的访问. 2, 文件操作,Namenod ...
- OpenStack (glance 镜像服务)
glance介绍 glance 提供云虚拟机上的服务镜像(Image)功能,该模块可看成车间里的模具生产部门,其功能包括虚拟机镜像的查找.注册和检索等.该模具最基本的使用方式就是在为云虚拟机实例提供安 ...
- springboot注解开发
可以毫不夸张地说,这篇文章介绍的 Spring/SpringBoot 常用注解基本已经涵盖你工作中遇到的大部分常用的场景.对于每一个注解我都说了具体用法,掌握搞懂,使用 SpringBoot 来开发项 ...
- 昨晚12点,女朋友突然问我:你会RabbitMQ吗?我竟然愣住了。
01为什么要用消息队列? 1.1 同步调用和异步调用 在说起消息队列之前,必须要先说一下同步调用和异步调用. 同步调用:A服务去调用B服务,需要一直等着B服务,直到B服务执行完毕并把执行结果返回给A之 ...
- Java程序操作HBase
package com.zy.test; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import ...
- HDOJ 1242
纠结1242很久了,查了题解才发现要优先队列才能成功 http://blog.chinaunix.net/uid-21712186-id-1818266.html 使人开窍之文章 优先队列,已经不算是 ...