JavaScript Fundamentals: The Whys and Hows of BigInt

Поделиться
HTML-код
  • Опубликовано: 2 ноя 2022
  • JavaScript has some issues with very large numbers. The creation of the BigInt type has helped with that. In this tutorial we are going to take a look at the problem and then how to use BigInt to overcome that.
    Would you like to help keep this channel going?
    www.patreon.com/bePatron?u=73...
    Follow me on Medium: / stevenhancock83
    Unlimited access to EVERY course for one low price: allthingsjavascript.teachable...
    Access to EVERY course via subscription (get 1 month free): www.skillshare.com/r/profile/...
    Courses offered on Udemy at a discount (access from my site): allthingsjavascript.com/course...
    For more resources on JavaScript:
    www.allthingsjavascript.com
    #javascript #AllThingsJavaScriptLLC

Комментарии • 19

  • @joonapasanen569
    @joonapasanen569 2 месяца назад

    Clear explanation! The n appended to the end of the bigInt was very confusing before watching this.

  • @BlaBlaBlaInDaHouse
    @BlaBlaBlaInDaHouse Год назад +1

    Another great explanation, thank you for this video!

  • @jaycortes2113
    @jaycortes2113 6 месяцев назад

    Thank you Sir! It's really clear now.

  • @jamilsamir1357
    @jamilsamir1357 Год назад

    Good day sir. Please could you do a video to explain Matrix iteration using Symbol.iterator in the chapter 6 of eloquent JavaScript (Secret life of objects). A lot of people have a problem with that section because the author kind of skipped explaining the code. The code is a bit tricky. I hope you get to see this cos i really need your help.

    • @AllThingsJavaScript
      @AllThingsJavaScript  Год назад

      I have a couple of tutorials on iterators and one on symbols, but to make sure I'm tackling what you would like, could you post the code? I found a copy of the book, but I'm not sure what you are referring to. Maybe this copy is too old.

    • @jamilsamir1357
      @jamilsamir1357 Год назад

      @@AllThingsJavaScript Ok thank you so much sir. Here is the code. There are two classes. One is a class Matrix. The second is a class MatrixIterator. The author decided to created the MatrixIterator class seperately and feed it to the Matrix Class using:
      Matrix.prototype[Symbol.iterator] = function() {
      return new MatrixIterator(this);
      };
      The author decided not to write the [Symbol.iterator] code directly in the Matrix class as a method. He wrote it separately to show us how to add methods without needing to edit the main class. Here is the code.
      First part( The Matrix Class):
      Let’s implement an iterable data structure. We’ll build a matrix class, acting as a two-dimensional array.
      class Matrix {
      constructor(width, height, element = (x, y) => undefined) {
      this.width = width;
      this.height = height;
      this.content = [];
      for (let y = 0; y < height; y++) {
      for (let x = 0; x < width; x++){
      this.content[y * width + x] = element(x, y);
      }
      }
      }
      get(x, y) {
      return this.content[y * this.width + x];
      }
      set(x, y, value) {
      this.content[y * this.width + x] = value;
      }
      }
      The second part( Class MatrixIterator):
      class MatrixIterator {
      constructor(matrix) {
      this.x = 0;
      this.y = 0;
      this.matrix = matrix;
      }
      next() {
      if (this.y == this.matrix.height) return {done: true};
      let value = {x: this.x,
      y: this.y,
      value: this.matrix.get(this.x, this.y)
      };
      this.x++;
      if (this.x == this.matrix.width) {
      this.x = 0;
      this.y++;
      }
      return {value, done: false};
      }
      }
      Matrix.prototype[Symbol.iterator] = function() {
      return new MatrixIterator(this);
      };
      Now the author creates an instance using the new keyword:
      Let matrix = let matrix = new Matrix(2, 2, (x, y) => `value ${x},${y}`);
      for (let {x, y, value} of matrix) {
      console.log(x, y, value);
      }
      // → 0 0 value 0,0
      // → 1 0 value 1,0
      // → 0 1 value 0,1
      // → 1 1 value 1,1
      Can i also mail you the book sir, if you could give me ur mail??

    • @jamilsamir1357
      @jamilsamir1357 Год назад

      Please if it would not be much stress to you sir, could you show the 2 methods that can be used to write that code. That is if we wanted to write the [SymbolIterator] directly in the class. And also if we want to write it as the author did in the book.
      Particularly sir, i have a problem with understanding how the constructor(matrix) in the MatrixIterator class is connecting with the main Matrix class. I know they were linked through prototype. I understand prototype to an extent. But i do not really understand how the constructor in the MatrixIterator receives the argument (matrix) from the Matrix class. When i check the Matrix class on console using the new instance matrix. It reveals:
      matrix= {width: 2, height: 2, content[array]}
      Now how is the MatrixIterator constructor able to recieve this information from the main class. And also, why did the author call the MatrixIterator class with a new keyword when he linked it to the Matrix prototype.
      Its all really confusing sir. Thanks alot in advance

    • @jamilsamir1357
      @jamilsamir1357 Год назад

      I can post the link to the chapter directly sir. But youtube seems to remove it instantly. I could tweak it so it doesn't look like a link. But you would need to change (dot) in the link to (.) And change (slash) to (/) to make d link work. Thanks sir.
      eloquentjavascriptdotnetslash06_objectdothtml

    • @AllThingsJavaScript
      @AllThingsJavaScript  Год назад

      @@jamilsamir1357 Thanks for posting the code. Let me spend some time with this and hopefully get something put together. My address: 733 N. Pinnacle Ln., Saratoga Springs, UT 84045

  • @jamilsamir1357
    @jamilsamir1357 Год назад

    Am sorry my comment strays from this video topic, i just needed help n thought i should comment on your latest video to increase your chances of seeing my comment.