Horatiu Jeflea
Horatiu Jeflea

Reputation: 7414

How do I know the type of a function parameter in javascript

function f(a, b) {}

Taking a sample function f in javascript, how do I know how objects a and b should look like ?

In Java for example, the class is self-documenting the expected object:

class A {
   private int c;
   private String d;
   private E e;
}

But how do I create the object in javascript, not knowing how it should look like, but making it valid for the function to run properly ?

The function f can be from a 3rd party lib, another module from the project ...

Upvotes: 0

Views: 2301

Answers (1)

Quentin
Quentin

Reputation: 944110

JavaScript is a dynamically typed language. It does not enforce types for function parameters.

If you want to know what values a function expects to be passed to it you have two basic options:

  • Read the documentation for the function
  • Read the source code of the function

Upvotes: 3

Related Questions