Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Functions Pass Information Into Functions Pass Multiple Arguments to a Function

J A
seal-mask
.a{fill-rule:evenodd;}techdegree
J A
Full Stack JavaScript Techdegree Student 4,619 Points

Is there a way to enforce types for parameters?

In other languages like Java, Python and PHP you can (and in some cases must) declare the type of parameters for a function. Does JavaScript have a notion of type hinting parameters? For example, in this video, there is nothing to prevent someone from calling the getArea() function with a String or Object argument instead of a Number.

Related to that, if there is no type hinting, is there a way to overload a function so that the same function name can be used with different numbers or types of arguments?

1 Answer

Steven Parker
Steven Parker
217,573 Points

JavaScript is a loosely typed language, meaning you don't have to specify what type of information will be stored in a variable in advance. Because of this, it has no equivalent to overloading as found in strongly typed languages.

There is a derivative language called TypeScript that is strongly typed, and it does implement overloading.