Consider using function to check type of variable

I think we should we function to check type of variable like underscore or lodash to make it more flexible or easier to test
Merge pull request #2210 from MQuy/patch-1

Consider using function to check type of variable