JavaScript的数据类型在大的方向上分为两类:1)primitive types and 2)object tyeps。
其一 primitive types包括常规的 numbers,string, booleans 以及特殊类型的 null 和 undefined。而且以上五类都是immutuable types;
其二,object types 包括object,以及特殊类型的object即array。其他比如 Set,Map,typed array, RegExp and Date types.
一、Numbers
Numeric literal 表示 十六进制,二进制和八进制:
- //integer literals
- > 0xff
- 255
- > 0b1011
- 11
- > 0o377
- 255
- > 377
- 377
- //floating-point literals
- undefined
- > 6.02e23
- 6.02e+23
- > 1.47e-23
- 1.47e-23
- //Arithmetic
- Math.hypo
- //Infinity
- Infinity // A positive number too big to represent
- Number.POSITIVE_INFINITY // Same value
- 1/0 // => Infinity
- Number.MAX_VALUE * 2 // => Infinity; overflow
- -Infinity // A negative number too big to represent
- Number.NEGATIVE_INFINITY // The same value
- -1/0 // => -Infinity
- -Number.MAX_VALUE * 2 // => -Infinity
- NaN // The not-a-number value
- Number.NaN // The same value, written another way
- 0/0 // => NaN
- Infinity/Infinity // => NaN
- Number.MIN_VALUE/2 // => 0: underflow
- -Number.MIN_VALUE/2 // => -0: negative zero
- -1/Infinity // -> -0: also negative 0
- -0
- // The following Number properties are defined in ES6
- Number.parseInt() // Same as the global parseInt() function
- Number.parseFloat() // Same as the global parseFloat() function
- Number.isNaN(x) // Is x the NaN value?
- Number.isFinite(x) // Is x a number and finite?
- Number.isInteger(x) // Is x an integer?
- Number.isSafeInteger(x) // Is x an integer -(2**53) < x < 2**53?
- Number.MIN_SAFE_INTEGER // => -(2**53 - 1)
- Number.MAX_SAFE_INTEGER // => 2**53 - 1
- Number.EPSILON // => 2**-52: smallest difference between numbers
- // 浮点数
- 18,437,736,874,454,810,627 只有这么多浮点数,能被表示出来。
- // rouding problems
- //BigInt
- //Date and time
- let timestamp = Date.now(); // The current time as a timestamp (a number).
- let now = new Date(); // The current time as a Date object.
- let ms = now.getTime(); // Convert to a millisecond timestamp.
- let iso = now.toISOString(); // Convert to a string in standard format.
二、String and Text
- // 1.string literals
- // 2.escape sequences
- // 3.string methods
- // 4.template literals (tagged template literals)
- // 5.Pattern Matching
- /[1-9][0-9]*/;
三、Boolean Values
只有 true 和 false 这两项。
四、null and undefined
- > typeof(null)
- 'object'
五、Symbols
- let s = Symbol.for("shared");
- let t = Symbol.for("shared");
- s === t // => true
- s.toString() // => "Symbol(shared)"
- Symbol.keyFor(t) // => "shared"
六、Global
七、Immutable Primitives and Mutable Object Referece
- > function equalArray(a, b) {
- ... if (a === b) return true;
- ... if (a.length !== b.length) return false;
- ... for (let i = 0; i < a.length; i++) {
- ..... if (a[i] !== b[i]) return false;
- ..... }
- ... return true;
- ... }
八、Type Conversions
implicite conversion and explicite conversions
九、Variable Declaration and Assignment
- // Destructuring Assignment
- [x,y] = [x+1,y+1]; // Same as x = x + 1, y = y + 1
- [x,y] = [y,x]; // Swap the value of the two variables
- // Same as const sin=Math.sin, cos=Math.cos, tan=Math.tan
- const {sin, cos, tan} = Math;
- //此处与python的用法完全一致。
行业趋势—游戏行业市场营销往精细化发展 2020年初突发的疫情防控导致游戏行业的...
昨天下午,一则朋友圈截图被米友刷屏。 原来,流星加速器是灵匠创投旗下网站,网...
11月17日消息,国际数据公司(IDC)日前发布的《中国金融云市场(2020上半年)跟踪》...
【51CTO.com快译】朋友和熟人常问我可以从哪里开始学习Kubernetes、如何开始学习...
浙江深大智能集团专注于提供智慧旅游全产业链产品创新、产业规划和运营服务,致力...
对于一个企业的网站来说,空间起着至关重要的作用,要想在后期的推广中取得好的...
1.简介 这篇文章其实很简单,就是为下一篇文章做一个铺垫,所以宏哥给小伙伴或童...
TOP云 (west.cn)6月2日消息,小编在社交媒体上发现, 英文域名 napkin.com和Gr...
今天给大伙介绍一下 RPA,有时候你可能会使用代码去编写自动化相关的操作,不过...
直播主题 Tair(Redis)行业场景深度剖析-生活出行的计算与应用 直播时间 5月20日 ...