-1

I have read this but there is no answer for my question: var functionName = function() {} vs function functionName() {}

Suppose I have a function variable and would like to call it in an if statement.

    var myFunc = function() {
        // very long code
    }
    if (true) myFunc;

Of course the above if statement would not work. How do I do that? Thanks.

Community
  • 1
  • 1
ngungo
  • 3,912
  • 4
  • 23
  • 34
  • Have a look at the MDN JavaScript Guide to learn the basics about functions: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions. – Felix Kling Feb 01 '14 at 17:19
  • 1
    Of course you are right. I just have a bad example to illustrate my problem. Let me rethink for a better example. :) – ngungo Feb 01 '14 at 17:25

1 Answers1

3

You just have to invoke it as a function:

myFunc();
Rob Hruska
  • 111,282
  • 28
  • 160
  • 186