All about the BigInt - New Javascript Data Type
HTML-код
- Опубликовано: 13 июл 2024
- We will take a dive into a ECMAscript 2020 feature coming soon to Javascript: the BigInt primitive data type. Learn everything you need to know about the bigInt in this video and level up your Javascript skills!
Optional Chaining & Nullish Coalescing Operator: • Optional Chaining & Nu...
Four Promise Functions: • Promise.all | Promise....
🗄 Resources:
ECMAscript Finished Proposals: github.com/tc39/proposals/blo...
MDN BigInt: developer.mozilla.org/en-US/d...
Amazing article: www.smashingmagazine.com/2019...
🔑 Key Concepts:
- BigInt
#BigInt #DataTypes #JavaScript2020 Наука
Hey guys, Justin here! I just realized that the sort() did not sort it correctly.... hmm 🤔
After doing some digging, I realized that the sort() function without any parameters actually sorts them in the LEXICAL ordering, not the actual number values itself! So sort() between a mixture of numbers and bigInts will only work properly when dealing with non-negative numbers
To be precise, it will coerce the number into a string and sort them by their character order in UTF-16. So, no, they won't work properly to sort numbers.
```
let arr = [1,2,3,10,20,30,100,200,300];
arr.sort() // [ 1, 10, 100, 2, 20, 200, 3, 30, 300 ]
```
if you spell out the sort mechanism it will work:
[10, 5, 15n, 0, -1, 20, -2n, 25, -3n, 30, -4, -5].sort((a, b) => {
if (a > b) {
return 1;
} else if (a < b) {
return -1;
} else if (a === b) {
return 0;
}
})
This channel is so underrated. Thank you so much for providing easy-to-understand videos. These kinds of videos are rare in the world of programming. Now I want to know about Symbol too :)
WOW, ur accent is easy to understand and u got perfect timing of explaining things. Continue what your doing Justin One day you will reach million subcribers. If possible please make full tutorial on JS . Thank you
this is extremely informative! keep making such videos brother.
Succinct explanation with the necessary amount of appreciation. Subscribed.
BigInt has a lot of potential with bitwise operators and binary data processing.
But I think the most common use case for BigInt will be emulating 64-bit integers; especially in context of BigInt64Array and it's unsigned counterpart.
Thanks Justin, for the clear-cut explanation. I'm on the same boat as you, won't be needing to use BigInt anytime soon. That said, I'd also like to be aware about its use cases.
Love this video. It taught me a lot of things 🖤
Thank you so much for it. You said that maybe you will never use BigInt. But It helped me making a project asked in an internship interview.
Thank you, Justin .
thank you very much for this information
you have cool style of explaining.
subscribed 👍
you got the point bro about 'SYMBOL'
Nice explaination
Thank you :)
well, as a fun exercise for a newbie front end dev, i wanted to create an "incremental" game (kind of useless game for people who like to see unnecessarily large numbers increase forever):D i was'nt aware at first of the 10^308 limit of the number type of javascript, this might be the solution i need !! i might need to restart my app from the start though ....
🔥
sort works because it by default converts every value to a string. that is why it is possible to sort them but the result will be unexpected, like in your example -1 will be before -4n
thankyou
The methods you've mentioned are remotely connected to immutability, and has outright nothing to do with primitive values from non-primitive ones. for instance, there are other methods that alter the memory location being by referenced by variables in place, rather than the returning the result of the computation back (and printing them out to stdout within this repl chrome console prompt).
As for arrays, their typical assignment gets them to copy the plain reference, rather than allocating yet another place at memory to accommodate the same value of the datatype initially referenced.
You've honestly mixed and matched between js concepts at first, and the clip should have been more confined to bigint itself which was really comprehensive. thanks!
bigint has lot of scope for web3
symbol is an anonymous datatype :)
I want BigFloat
Why the fuck didn't they add a way to fix 0.1+0.2 not being equal to 0.3 alongside with this? 😐