0

I am new to javascript and I want to know that is there a way to declare a function without defining it. As we do in C:

int sum(int, int);

and then we can write it's definition later. As in:

int sum(int A, intB){
    return A+B;
}

Do we have a way in javascript to just declare a function without defining it?

sabertooth1990
  • 1,048
  • 1
  • 13
  • 19
  • 1
    No. Functions are hoisted to the top of the scope, so they are defined before anything else, regardless of where they actually are in the code. Hence, you can use a function anywhere in your code, regardless of where the function is actually defined. – Reid Aug 31 '12 at 18:53
  • The reason you need to do that in C is so the compiler can perform proper type checking. You shouldn't need to worry about this since JavaScript is interpreted. Are you running into a specific problem? – Joel Aug 31 '12 at 22:27
  • I need it so that my code passes through JSLint successfully. – sabertooth1990 Sep 18 '12 at 13:46

0 Answers0