<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
</body>
<script>
// 1. 十進制數值變量 0-9
let num1 =10;
console.log(num1);
// 2. 十六進[0x]制數值變量 0-9 A-F(10-15)
let num2 = 0xAB; // 11 * 16^0 + 10 * 16^1 = 171
console.log(num2); // 171
// 3. 八進制[0o]數值變量 0-7
let num3 = 0o10; // 0 * 8^0 + 1 * 8^1 = 8
console.log(num3); // 8
// 4. 浮點數
let money = 10.3;
console.log(money);
// 5. 科學計數法 5 * 10^10
let distance = 5e-10;
console.log(distance);
// 6. 浮點數之間的運算會出現精度丟失,所以儘量避免浮點數相等的判斷條件
console.log(0.1 + 0.2); // 0.30000000000000004
console.log(0.1 + 0.3); // 0.4
console.log(1 - 0.9); // 0.09999999999999998
// 7. 計算機中能夠存儲的最大值
console.log(Number.MAX_VALUE); // 1.7976931348623157e+308
// 8. 計算機中能夠存儲的最小值
console.log(Number.MIN_VALUE); // 5e-324
</script>
</html>
JavaScript數值類型
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.