Which one is better approach to find whether a variable is of type function
typeof(methodName) == typeof(Function)
or
typeof methodName === 'function'
There are two things going on here:
typeof
is an operator, not a function, don't use them'function'
or typeof Function
(which will always return 'function'
unless someone is screwing around and overwriting native objects). Use the string, it requires less work and isn't subject to the aforementioned screwing around.i.e. Use:
typeof methodName === 'function'
The second one has better performance and used in many javascript library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With