Added new information about bigInt

This commit is contained in:
Ajit Singh 2019-11-22 20:23:35 +05:30 committed by GitHub
parent c7a9080934
commit 12acb05343
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,7 +10,7 @@ message = 123456;
Programming languages that allow such things are called "dynamically typed", meaning that there are data types, but variables are not bound to any of them.
There are eight basic data types in JavaScript. Here, we'll cover them in general and in the next chapters we'll talk about each of them in detail. We will cover about bigInt later for now you can acess [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) docs for it
There are eight basic data types in JavaScript. Here, we'll cover them in general and in the next chapters we'll talk about each of them in detail.
## A number
@ -182,11 +182,28 @@ The `symbol` type is used to create unique identifiers for objects. We mention i
## BigInt
In JavaScript, the Number type cannot represent integer values larger than 2<sup>53</sup>. This limitation has forcedmany of us to use inefficient workarounds. BigInt is a new data type intended to fix just that.
In JavaScript, the Number type cannot represent integer values larger than 2<sup>53</sup>-1. This limitation has forced many of us to use inefficient workarounds. BigInt is a new data type intended to fix just that. A BigInt is created by appending n to the end of an integer literal — 10n — or by calling the function BigInt().
A BigInt is created by appending n to the end of an integer literal — 10n — or by calling the function BigInt().
```js run
const theBiggestInt = 9007199254740991n;
Right now it sis compatible with firefix and chrome but is not supported in Safari.
const huge = BigInt(9007199254740991);
alert(typeof biggestInt); // shows "bigint"
alert(typeof huge); // shows "bigint"
```
Bigint can mostly be used like number but there are some key differences
- Most math operatioons work on it normally
- It cannot be mixed and match with number while apllying binary operations it has to be coerced into each other but be careful it can lead to some precision losses
- The / operator also works as expected with whole numbers. However, since these are BigInts and not BigDecimals, this operation will round towards 0, which is to say, it will not return any fractional digits.
To know more in detail about the java script newest addition in prmitive types please visit [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) docs for it
```smart header="Compatability issues"
Right now it only compatible with firefox and chrome but is not supported in Safari.
```
## The typeof operator [#type-typeof]
@ -234,7 +251,7 @@ The last three lines may need additional explanation:
## Summary
There are 7 basic data types in JavaScript.
There are 8 basic data types in JavaScript.
- `number` for numbers of any kind: integer or floating-point.
- `string` for strings. A string may have one or more characters, there's no separate single-character type.