1. Overview There are two ways to create const bigint = 1234567890123456789012345678901234567890n; const sameBigint = BigInt("1234567890123456789012345678901234567890"); const bigintFromNumber = BigInt(10); // Same as 10n 2. Attributes1. Mathematical operators For example: alert(1n + 2n); // 3 alert(5n / 2n); // 2 Note: The result of the division 5/2 is rounded towards zero, and the result obtained after rounding has no decimal part. All operations on You cannot mix alert(1n + 2); // Error: Cannot mix BigInt and other types If necessary, you should convert them explicitly: using let bigint = 1n; let number = 2; // Convert number to bigint alert(bigint + BigInt(number)); // 3 // Convert bigint to number alert(Number(bigint) + number); // 3 The conversion is always silent and never raises an error, but if the bigint is too large to fit in the numeric type, the extra bits will be truncated, so such conversions should be done with caution. The unary addition operator +value is a well-known method for converting value to a numeric type. To avoid confusion, unary addition is not supported in let bigint = 1n; alert( +bigint ); // error
2. Comparison Operators Comparison operators, such as < and >, have no problem using them to compare alert( 2n > 1n ); // true alert( 2n > 1 ); // true Note: Because alert( 1 == 1n ); // true alert( 1 === 1n ); // false 3. Boolean operationsWhen inside an if or other Boolean operation, bigint behaves like number. Example: In if, bigint 0n is false, and other values are true: if (0n) { // will never be executed} Boolean operators For example , ||, && and other operators handle bigint in a similar way to number: alert( 1n || 2 ); // 1 (1n is considered true) alert( 0n || 2 ); // 2 (0n is considered false) Note: This method recommends using For engines that don't support Conclusion Based on This concludes this article on summarizing the common properties of the BigIn function in JavaScript. For more information about the common properties of the BigIn function in JavaScript, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Use non-root users to execute script operations in docker containers
>>: Implementation of form submission in html
Table of contents 1. Pull the image 2. Create a R...
Preface ORDER BY 字段名升序/降序, I believe that everyon...
1. Command Introduction The ifconfig (configure a...
The operating system for the following content is...
<br />Semanticization cannot be explained in...
Preface During the development process, we often ...
1. Modify the firewall configuration file # vi /e...
Preface In daily work, we sometimes run slow quer...
1. Delete folders Example: rm -rf /usr/java The /...
What is bond NIC bond is a technology that is com...
Linux is currently the most widely used server op...
background If the catalina.out log file generated...
Table of contents Preface 1. Rendering 2. Code 3....
Let's take a look at the process of installin...
1. Create a new configuration file docker_nginx.c...