首頁>技術>

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> 0xff255> 0b101111> 0o377255> 377377//floating-point literalsundefined> 6.02e236.02e+23> 1.47e-231.47e-23//Arithmetic Math.hypo//InfinityInfinity                    // A positive number too big to representNumber.POSITIVE_INFINITY    // Same value1/0                         // => InfinityNumber.MAX_VALUE * 2        // => Infinity; overflow-Infinity                   // A negative number too big to representNumber.NEGATIVE_INFINITY    // The same value-1/0                        // => -Infinity-Number.MAX_VALUE * 2       // => -InfinityNaN                         // The not-a-number valueNumber.NaN                  // The same value, written another way0/0                         // => NaNInfinity/Infinity           // => NaNNumber.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 ES6Number.parseInt()       // Same as the global parseInt() functionNumber.parseFloat()     // Same as the global parseFloat() functionNumber.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 - 1Number.EPSILON          // => 2**-52: smallest difference between numbers// 浮點數 18,437,736,874,454,810,627 只有這麼多浮點數,能被表示出來。// rouding problems //BigInt//Date and timelet 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          // => trues.toString()     // => "Symbol(shared)"Symbol.keyFor(t) // => "shared"
六、GlobalGlobal constants like undefined, Infinity, and NaNGlobal 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
> 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.tanconst {sin, cos, tan} = Math;//此處與python的用法完全一致。

12
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • web前端開發必備技能,一起get