Question

Can I declare methods that will be used later in JavaScript similarly to C++ Function prototypes.

Was it helpful?

Solution

No, there is no such thing as function declarations in Javascript. It doesn't matter what parameters you define in a function, it can be called with any set of values. Example:

function test(a, b) {}

test(); // values are not required for all parameters

test(1, 2, 3, 4); // values are not limited to the number of parameters

Making the code pass stricter validation is another matter. Then you have to define the functions exactly as you use them. The point of the validation in this case is to keep you from misusing the lack of declarations in the language, as it results in code that is harder to follow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top