Is there or isn't there an integer type in JavaScript?

前端 未结 4 1485
南旧
南旧 2020-12-29 01:19

I am just starting to learn Javascript and I immediately got confused by seemingly contradictory statements in Mozilla\'s A re-introduction to JavaScript (JS tutorial).

4条回答
  •  半阙折子戏
    2020-12-29 01:36

    I should mention that there is actually a type called BigInt which represents a true integer.

    However, because it can't be used with Number and is generally only a good idea to use for larger numbers, I wouldn't advise it.

    I thought it was worth a mention though.

    var n = BigInt(1337);
    console.log(typeof n); //prints "bigint"
    

提交回复
热议问题