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 ...
随机推荐
- FFT,NTT 笔记
FFT 简介 FFT是干啥的?它是用来加速多项式乘法的.我们平时经常求多项式乘法,比如\((x+1)(x+3)=(x^2+4x+3)\).假设两个式子都是\(n\)项(不足的补0),那朴素的算法是\( ...
- 2021年,python的入门基础-----基础一
先记录下pycharm编译器相关的信息 1.某些常用快捷键: Ctrl+/ 注释: Tab缩进,shift+Tab; Ctrl+Z 撤销 2.设置界面编辑风格: File>Settings> ...
- CSS3 Flex Box 弹性盒子、弹性布局
目录 1. 概要 2. justify-content 属性 3. align-items 属性 4. flex-wrap 属性 5. align-content 属性 6. 居中 7. align- ...
- jQuery——操作DOM
所谓Web体验,就是Web服务器与Web浏览器之间的合作.过去,都是由服务器生成HTML文档,然后浏览器负责解释并显示该文档.后来,我们可以用CSS技术来动态修改页面的外观. ###操作属性 jQue ...
- ubuntu14.04 ssh允许root用户远程登录
vi /etc/ssh/sshd_config #注释掉 #PermitRootLogin without-password # Authentication: LoginGraceTime 120 ...
- 飞塔创建IPSec
5.2和5.4版本飞塔建立IPSec VPN时,必须在两端添加完策略.路由后IPSec才会起来.
- 关于SANGFOR AC记录上网记录
1.查看加密APP的访问记录,不支持推送证书的方式.也就是这种的是没办法查看到的:2.查看加密网站的访问记录,通过推送证书,电脑可以查看到:手机端安卓的不能,苹果可以,但是不建议做,适用性不好:3.查 ...
- Java 复习整理day10
package com.it.demo01_quickstart; /* 案例: 讲解网络编程相关概念. 网络编程简介: 概述: 网络编程也叫: 套接字编程, Socket编程, 就是用来实现 网络互 ...
- Web程序设计基础期末大作业——模仿QQ飞车手游S联赛官网编写的网页
QQ飞车手游是我非常喜欢的游戏,也是我现在为数不多的常在玩的游戏,刚好我Web程序设计基础的大作业是要做一套网站,我就借此机会模仿飞车S联赛官网的页面自己做了一个网页,又加了一些自己的元素,由于我做这 ...
- [USACO12FEB]Symmetry
传送门: https://www.luogu.com.cn/problem/P3046 https://ac.nowcoder.com/acm/contest/6306/G 题意 给定n个不同的点,求 ...