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. Routine Subroutine Coroutine 子程序 协程 子例程

    https://en.wikipedia.org/wiki/Subroutine In computer programming, a subroutine is a sequence of prog ...

  2. Eclipse+Maven+Spring

    1.首先按照how2j教程搭建Maven项目:http://how2j.cn/k/maven/maven-eclipse-maven-project/1332.html 2. 刚建好时没有资源文件夹的 ...

  3. PowerBI官方文档

    Excel 帮助和学习 - Microsoft 支持https://support.microsoft.com/zh-cn/excel Power Query M 公式语言引用 - PowerQuer ...

  4. 使用Docker部署监控系统,Prometheus,Grafana,监控服务器信息及Mysql

    使用Docker部署监控系统,Prometheus,Grafana,监控服务器信息及Mysql 一.docker部署prometheus监控系统 1.1 配置安装环境 1.1.1 安装promethe ...

  5. (12)Linux文件系统层次结构

    在 Linux 操作系统中,所有的文件和目录都被组织成以一个根节点"/"开始的倒置的树状结构 文件系统的最顶层是由根目录开始的,系统使用"/"来表示根目录,在根 ...

  6. 四十三:漏洞发现-WEB应用之漏洞探针类型利用修复

    已知CMS 如常见的dedecms,discuz,wordpress等源码结构,这种一般采用非框架开发,但是也有少部分采用框架类开发,针对此类源码程序的安全监测, 我们要利用公开的漏洞进行测试,如不存 ...

  7. Codeforces Round #594 (Div. 2) D1 - The World Is Just a Programming Task

    思路:枚举换的位置i,j 然后我们要先判断改序列能否完全匹配 如果可以 那我们就需要把差值最大的位置换过来 然后直接判断就行

  8. Codeforces Round #642 (Div. 3)

    比赛链接:https://codeforces.com/contest/1353 A - Most Unstable Array 题意 构造大小为 $n$,和为 $m$ 的非负数组 $a$,使得相邻元 ...

  9. codeforces628D. Magic Numbers (数位dp)

    Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in d ...

  10. Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water

    题目链接:B.New Theatre Square 题意: 你要把所有"." 都变成"*",你可以有两个选择,第一种就是一次铺一个方块(1*1),第二种就是同一 ...