温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

JavaScript的两大类内建数据类型是怎样的

发布时间:2021-09-30 11:21:56 来源:亿速云 阅读:126 作者:柒染 栏目:web开发

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

//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

  • Global constants like undefined, Infinity, and NaN

  • Global functions like isNaN(), parseInt() (&sect;3.9.2), and eval() (&sect;4.12)

  • Constructor functions like Date(), RegExp(), String(), Object(), and Array()  (&sect;3.9.2)

  • Global objects like Math and JSON (&sect;6.8)

七、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的用法完全一致。

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI