JavaScript的两大类内建数据类型

 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 表示 十六进制,二进制和八进制:

 
 
 
  1. //integer literals 
  2. > 0xff 
  3. 255 
  4. > 0b1011 
  5. 11 
  6. > 0o377 
  7. 255 
  8. > 377 
  9. 377 
  10. //floating-point literals 
  11. undefined 
  12. > 6.02e23 
  13. 6.02e+23 
  14. > 1.47e-23 
  15. 1.47e-23 
  16. //Arithmetic  
  17. Math.hypo 
  18.  
  19. //Infinity 
  20. Infinity                    // A positive number too big to represent 
  21. Number.POSITIVE_INFINITY    // Same value 
  22. 1/0                         // => Infinity 
  23. Number.MAX_VALUE * 2        // => Infinity; overflow 
  24.  
  25. -Infinity                   // A negative number too big to represent 
  26. Number.NEGATIVE_INFINITY    // The same value 
  27. -1/0                        // => -Infinity 
  28. -Number.MAX_VALUE * 2       // => -Infinity 
  29.  
  30. NaN                         // The not-a-number value 
  31. Number.NaN                  // The same value, written another way 
  32. 0/0                         // => NaN 
  33. Infinity/Infinity           // => NaN 
  34.  
  35. Number.MIN_VALUE/2          // => 0: underflow 
  36. -Number.MIN_VALUE/2         // => -0: negative zero 
  37. -1/Infinity                 // -> -0: also negative 0 
  38. -0 
  39.  
  40. // The following Number properties are defined in ES6 
  41. Number.parseInt()       // Same as the global parseInt() function 
  42. Number.parseFloat()     // Same as the global parseFloat() function 
  43. Number.isNaN(x)         // Is x the NaN value? 
  44. Number.isFinite(x)      // Is x a number and finite? 
  45. Number.isInteger(x)     // Is x an integer? 
  46. Number.isSafeInteger(x) // Is x an integer -(2**53) < x < 2**53? 
  47. Number.MIN_SAFE_INTEGER // => -(2**53 - 1) 
  48. Number.MAX_SAFE_INTEGER // => 2**53 - 1 
  49. Number.EPSILON          // => 2**-52: smallest difference between numbers 
  50. // 浮点数  
  51. 18,437,736,874,454,810,627 只有这么多浮点数,能被表示出来。 
  52. // rouding problems  
  53. //BigInt 
  54.  
  55. //Date and time 
  56. let timestamp = Date.now();  // The current time as a timestamp (a number). 
  57. let now = new Date();        // The current time as a Date object. 
  58. let ms = now.getTime();      // Convert to a millisecond timestamp. 
  59. let iso = now.toISOString(); // Convert to a string in standard format. 

 二、String and Text

 
 
 
  1. // 1.string literals 
  2. // 2.escape sequences  
  3. // 3.string methods 
  4. // 4.template literals (tagged template literals) 
  5. // 5.Pattern Matching  
  6. /[1-9][0-9]*/;  

 三、Boolean Values

只有 true 和 false 这两项。

四、null and undefined

 
 
 
  1. > typeof(null) 
  2. 'object' 

 五、Symbols

 
 
 
  1. let s = Symbol.for("shared"); 
  2. let t = Symbol.for("shared"); 
  3. s === t          // => true 
  4. s.toString()     // => "Symbol(shared)" 
  5. Symbol.keyFor(t) // => "shared" 

 六、Global

  • Global constants like undefined, Infinity, and NaN
  • Global functions like isNaN(), parseInt() (§3.9.2), and eval() (§4.12)
  • Constructor functions like Date(), RegExp(), String(), Object(), and Array() (§3.9.2)
  • Global objects like Math and JSON (§6.8)

七、Immutable Primitives and Mutable Object Referece

 
 
 
  1. > function equalArray(a, b) { 
  2. ... if (a === b) return true; 
  3. ... if (a.length !== b.length) return false; 
  4. ... for (let i = 0; i < a.length; i++) { 
  5. ..... if (a[i] !== b[i]) return false; 
  6. ..... } 
  7. ... return true; 
  8. ... } 

 八、Type Conversions

implicite conversion and explicite conversions

九、Variable Declaration and Assignment

 
 
 
  1. // Destructuring Assignment 
  2. [x,y] = [x+1,y+1];  // Same as x = x + 1, y = y + 1 
  3. [x,y] = [y,x];      // Swap the value of the two variables 
  4. // Same as const sin=Math.sin, cos=Math.cos, tan=Math.tan 
  5. const {sin, cos, tan} = Math; 
  6. //此处与python的用法完全一致。 

 【编辑推荐】

  1. 2021年比较适合用于Web开发的7种编程语言
  2. 为什么用Eclipse,VS Code不香吗?
  3. 权威数据来了,中国到底有多少个程序员?
  4. 10个实用的工具类网站你收藏了吗?
  5. 在2021年,可能会是前景比较好的五门编程语言

当前题目:JavaScript的两大类内建数据类型
分享地址:http://www.shufengxianlan.com/qtweb/news35/395185.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联