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 ...
随机推荐
- :setting:`task_soft_time_limit` celery 异步任务 执行时间限制 内存限制
https://docs.celeryproject.org/en/stable/userguide/configuration.html?highlight=control_exchange#new ...
- TCP介绍
TCP协议,传输控制协议(英语:Transmission Control Protocol,缩写为 TCP)是一种面向连接的.可靠的.基于字节流的传输层通信协议,由IETF的RFC 793定义. TC ...
- Shell 简单入门教程
大数据开发岗为什么要学习Shell呢?1)需要看懂大数据运维岗人员编写的Shell程序.2)偶尔会编写一些简单Shell程序来管理集群.提高开发效率 艺多不压身 Shell是一个命令行解释器,它接受应 ...
- react报错 TypeError: Cannot read property 'setState' of undefined
代码如下: class test extends Component { constructor(props) { super(props); this.state = { liked: false ...
- PowerBI数据建模时的交叉连接问题
方案一.在PowerPivot中,将其中一张表复制多份,分别与另一张表做链接. 方案二.在PowerQuery中,做多次合并查询,把所有数据集中在一张表中,方便后面的数据分析. 思考:不仅仅是在Pow ...
- (十六)配置多数据源,整合MybatisPlus增强插件
配置多数据源,整合MybatisPlus增强插件 多数据简介 MybatisPlus简介 1.案例实现 1.1 项目结构 1.2 多数据源配置 1.3 参数扫描类 1.4 配置Druid连接池 1.5 ...
- Java8新特性_四大内置核心函数式接口
Consumner : 消费型接口 Supplier :供给型接口 Function:函数式接口 Predicate:断言型接口 其他接口: 四大内置核心函数式接口: Consumner : 消费型接 ...
- 从微信小程序到鸿蒙js开发【05】——tabs组件&每日新闻
目录: 1.tabs, tab-bar, tab-content 2.tabs的事件处理 3.tabs实现的每日新闻 1.tabs, tab-bar, tab-content 上章说到,鸿蒙的list ...
- 如何获得svn的版本号信息?
方法一 popen(可获取命令行执行后的输出结果) 转载自: C++执行命令行指令并获取命令行执行后的输出结果 1 /* 2 Execute command line commands and ge ...
- Codeforces Round #675 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1422 A. Fence 题意 给出三条边 $a,b,c$,构造第四条边使得四者可以围成一个四边形. 题解 $d = max( ...