2018/9/6 プリミティブ・数値リテラル・メソッドについて javascript

十一章第六回 プリミティブについて2

特になし。ほとんど定義なので理解するだけ。

<!doctype html>
<html>
<head>
<title>test</title>
</head>
<body>

<script type=”text/javascript”>

console.log(“3/0= “+3/0); // Infinity
console.log(“-3/0= “+(-3/0));
console.log(“Infinityの型は “+(typeof (1/0))); // “number”
console.log(“Infinity-Infinity= “+(Infinity-Infinity)); // NaN
console.log(“Infinity/Infinity= “+(Infinity/Infinity));
console.log(“0/0= “+(0/0));
console.log(“”);

console.log(‘parseInt(“123px”)= ‘+(parseInt(“123px”))); // 123

console.log(‘Number(“123px=”)= ‘+(Number(“123px”))); // NaN

console.log(‘Number(“100.5”)= ‘+(Number(“100.5”))); // 123

console.log(‘parseInt(“100.5”)= ‘+(parseInt(“100.5”)));

console.log(‘parseInt(“10000”)= ‘+(parseInt(“10000”)));
console.log(‘parseInt(“10000”,2)= ‘+(parseInt(“10000”,2)));
console.log(‘parseFloat(“100.56fghr”)= ‘+(parseFloat(“100.536fghr”)));

console.log(“100<Infinity → ”+(100<Infinity));
console.log(“isFinite(-Infinity) = “+(isFinite(-Infinity)));
console.log(“isFinite(30) = “+(isFinite(30)));
console.log(“1e4= “+(1e4));
console.log(“3e-2= “+(3e-2));
console.log(“0xbfc2= “+(0xbfc2));
var a=30000;
console.log(a.toLocaleString()); // “30,000”
console.log(“1234.56789.toFixed(2) = “+1234.56789.toFixed(2));
console.log(Number.MAX_VALUE);

var a= Number.MAX_VALUE;
var b=a-1;
console.log(a===b); // true

</script>
</body>
</html>


結果

challenge.html:25 3/0= Infinity
challenge.html:26 -3/0= -Infinity
challenge.html:27 Infinityの型は number
challenge.html:28 Infinity-Infinity= NaN
challenge.html:29 Infinity/Infinity= NaN
challenge.html:30 0/0= NaN
challenge.html:31
challenge.html:33 parseInt(“123px”)= 123
challenge.html:35 Number(“123px=”)= NaN
challenge.html:37 Number(“100.5”)= 100.5
challenge.html:39 parseInt(“100.5”)= 100
challenge.html:41 parseInt(“10000”)= 10000
challenge.html:42 parseInt(“10000”,2)= 16
challenge.html:43 parseFloat(“100.56fghr”)= 100.536
challenge.html:45 100<Infinity → true
challenge.html:46 isFinite(-Infinity) = false
challenge.html:47 isFinite(30) = true
challenge.html:48 1e4= 10000
challenge.html:49 3e-2= 0.03
challenge.html:50 0xbfc2= 49090
challenge.html:52 30,000
challenge.html:53 1234.56789.toFixed(2) = 1234.57
challenge.html:54 1.7976931348623157e+308
challenge.html:58 true

 

コメントを残す

メールアドレスが公開されることはありません。