which is the most secure way to check variables type javascript

Posted by mck89 on Stack Overflow See other posts from Stack Overflow or by mck89
Published on 2010-05-12T08:02:08Z Indexed on 2010/05/12 8:04 UTC
Read the original article Hit count: 297

Hi, i need to check the type of a variable in javascript, i know 3 ways to do it:

instanceof operator: if(a instanceof Function)

typeof operator: if(typeof a=="function"

toString method (jQuery uses this): Object.prototype.toString.call(a) == "[object Function]"

Which is the most secure way to do type checking beetween these solutions? and why? Please don't tell me that the last solution is better only because jQuery uses that.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about variables