Search code examples
javascriptparseint

How parseInt() method return an integer


I read a post about parseInt() method of JavaScript from w3Scools site. Under "definition and usage" section it says,

The parseInt() function parses a string and returns an integer

In MDN site it says there are only 6 types of primitive types, but integer is not one of them.

I'm confused with this. If integer is not a type in JavaScript how a method return an integer. Can someone explain this.


Solution

  • The documentation that you read is misleading. The parseInt method returns a number, but it returns a number without anything after the decimal point.

    https://en.wikipedia.org/wiki/Integer