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 ...
随机推荐
- Enabling Session Persistence 粘性会话
NGINX Docs | HTTP Load Balancing https://docs.nginx.com/nginx/admin-guide/load-balancer/http-load-ba ...
- Solon rpc 1.3.1 发布,推出Cloud接口与配置规范
Solon 是一个微型的Java RPC开发框架.项目从2018年启动以来,参考过大量前人作品:历时两年,3500多次的commit:内核保持0.1m的身材,超高的跑分,良好的使用体验.支持:Rpc. ...
- 《进击吧!Blazor!》第一章 3.页面制作
作者介绍 陈超超Ant Design Blazor 项目贡献者拥有十多年从业经验,长期基于.Net技术栈进行架构与开发产品的工作,Ant Design Blazor 项目贡献者,现就职于正泰集团 写专 ...
- Spring Boot 基础,理论,简介
Spring Boot 基础,理论,简介 1.SpringBoot自动装配 1.1 Spring装配方式 1.2 Spring @Enable 模块驱动 1.3 Spring 条件装配 2.自动装配正 ...
- Java 高并发 解决方案
1.HTML静态化 2.图片服务器分离 3.数据库集群和库表散列 4.缓存 5.镜像 6.负载均衡 1)硬件四层交换 2)软件四层交换 一:高并发高负载类网站关注点之数据库 二:高并发高负载网站的系统 ...
- NodeMCU获取并解析心知天气信息
NodeMCU获取并解析心知天气信息 1 注册心知天气并获取私钥 打开心知天气网站,点击注册按钮 填写基本信息注册心知天气账号,登录注册所填写的邮箱点击链接进行账号激活,随后出现如下界面 点击登录按钮 ...
- 浅谈Winform控件开发(一):使用GDI+美化基础窗口
写在前面: 本系列随笔将作为我对于winform控件开发的心得总结,方便对一些读者在GDI+.winform等技术方面进行一个入门级的讲解,抛砖引玉. 别问为什么不用WPF,为什么不用QT.问就是懒, ...
- 基于C#/Winform实现的Win8MetroLoading动画
非常喜欢Metro风格的界面,所以想模仿一下一些UI效果的实现,网上找到了很多,但都是CSS3,WPF等实现,对于XAML和CSS3一窍不通,无奈下只有自己开始写. 下面是源码: 1 using Sy ...
- 零基础如何使用python处理字符串?
摘要:Python的普遍使用场景是自动化测试.爬取网页数据.科学分析之类,这其中都涉及到了对数据的处理,而数据的表现形式很多,今天我们来讲讲字符串的操作. 字符串是作为任意一门编程语言的基础,在P ...
- python爬虫笔记Day01
python爬虫笔记第一天 Requests库的安装 先在cmd中pip install requests 再打开Python IDM写入import requests 完成requests在.py文 ...