In JavaScript, is parseInt() a function or a method? (Some sources claim the former, while others the latter)

87 views Asked by At

I'm just trying to understand the difference between functions and methods, and parseInt() only brought more confusion to the table.

According to mdn web docs, it's a function:

The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).

While - for example - w3schools states it to be a method:

The parseInt method parses a value as a string and returns the first integer.

Which one is it, then - a function or a method? And for future cases, how can I intuitively 'tell the two apart'?

1

There are 1 answers

2
AKX On

Quoting the spec:

A primitive value is a member of one of the following built-in types: Undefined, Null, Boolean, Number, BigInt, String, and Symbol; an object is a member of the built-in type Object; and a function is a callable object. A function that is associated with an object via a property is called a method.

Since parseInt isn't associated with an object, it's a function, not a method.