0

How to check if there is a function declared ? The function name is available in variable. Example:

var n = 'f1';
if (!functionExists(n)) {
    //execute code when function not available
}
5
  • maybe typeof window[n] === 'function', will work for global functions only Commented Nov 9, 2015 at 14:11
  • @Tushar will only work for global function. Will never work with closure for example Commented Nov 9, 2015 at 14:11
  • I guess you could use (eval) but be really cautionous when using it. Commented Nov 9, 2015 at 14:12
  • Silly me answering a duplicate question when I should have answered the original. So now I have. Commented Nov 9, 2015 at 14:42
  • The mentioned SO answers are enough for me. Commented Nov 10, 2015 at 7:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.