JavaScript Numbers, Number Methods, isNaN | JavaScript Tutorial for Beginners

Поділитися
Вставка
  • Опубліковано 17 січ 2025

КОМЕНТАРІ • 9

  • @jiweihe3413
    @jiweihe3413 2 роки тому +3

    Thanks. The difference between global isNaN() and Number.isNaN is interesting.

  • @GoGetSP
    @GoGetSP 2 роки тому

    3:58
    console.log((142.035).toFixed(2));
    outputs - 142.03 // Why doesn't it output 142.04??

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      MDN is the source to help you with these questions: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

    • @GoGetSP
      @GoGetSP 2 роки тому

      @@DaveGrayTeachesCode Thanks for replying! I went to MDN docs .. came across an example
      2.55.toFixed(1)
      Returns '2.5' -> it rounds down as it can't be represented by a float // closest representable float is lower?
      What does that mean?

  • @GoGetSP
    @GoGetSP 2 роки тому

    Please tell one example of a parameter when
    Number.isNaN() will return true?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      Looks like you found this in another comment you posted, but Number.isNaN(0/0) returns true.

    • @GoGetSP
      @GoGetSP 2 роки тому

      @@DaveGrayTeachesCode Thankyou!
      Number.isNaN(0/0) //returns true?
      isNaN() - yes
      datatype Number-?
      console.log(Number.isInteger(0 / 0)); // returns false?

  • @Grihlo
    @Grihlo 2 роки тому +1

    Thank you for another lesson!
    Honestly I didn't get the concept of Number.isNaN()
    I went to MDN to get some more information about this method and can't say that it helped. I couldn't think of examples when Number.isNaN() can possibly return "true". But in MDN there are few examples of it -
    Number.isNaN(NaN); // true
    Number.isNaN(Number.NaN); // true
    Number.isNaN(0 / 0); // true