TypedArr (TA05)
1: const number = 12345;
2:
3: // 1. Convert to floating-point
4: const floatNumber = parseFloat(number);
5: console.log("Floating-point:", floatNumber); // Output: 12345
6:
7: // 2. Convert to BigInt
8: const bigIntNumber = BigInt(number);
9: console.log("BigInt:", bigIntNumber); // Output: 12345n
10:
11: // 3. Convert to binary
12: const binaryString = number.toString(2);
13: console.log("Binary:", binaryString); // Output: "11000000111001"
14:
15: // 4. Convert to boolean
16: const booleanValue = Boolean(number);
17: console.log("Boolean:", booleanValue); // Output: true
18:
19: // 5. Convert to character string
20: const charString = String.fromCharCode(number);
21: console.log("Character:", charString); // Output: "〹"
22:
23: // 5a. Convert to string (digits as string)
24: const stringValue = number.toString();
25: console.log("String:", stringValue); // Output: "12345"
Conversion Type JavaScript Code Output for 12345 Floating-point (Float) parseFloat(number) 12345 BigInt BigInt(number) 12345n Binary number.toString(2) "11000000111001" Boolean Boolean(number) true Character String String.fromCharCode(number) "〹" (Unicode char) String (Digits) number.toString() "12345" Floating-point: 12345 BigInt: 12345n Binary: 11000000111001 Boolean: true Character: 〹 String: 12345
TypedArr context:
ES6 context:
Binary context:
Comments (
)
)
Link to this page:
http://www.vb-net.com/JavascriptES6/TA05.htm
|
|