1

typeof new Number(1) will return "object", same with instantiated strings, etc.

Is it safe to use typeof myVar === "function" or are there any browsers that will return "object" when using the Function constructor (don't know why they should do, but maybe there is any one)?

headacheCoder
  • 4,503
  • 8
  • 30
  • 33
  • if you want to detect function objects, see also http://stackoverflow.com/questions/5999998/how-can-i-check-if-a-javascript-variable-is-function-type – mykhal Aug 23 '12 at 09:45

2 Answers2

0

You could use

if (myVar instanceof Function) 

instead. However, myVar instanceof Object would also be true, since it's a derived type. I'm not sure if this is "more" cross-browser compatible, but I'm fairly certain that it's part of ecma-standard.

jishi
  • 24,126
  • 6
  • 49
  • 75
0

I use it in all my applications and I never had problems. It's safe to use .

ECMAScript Definition

heat
  • 1,295
  • 9
  • 20