javascript - Why strict comparison(===) when checking typeof equality? -


say wanted function checked whether or not variable string, interwebs advised me follows:

function is_string(s) { return typeof s === 'string'; } 

but can't think of scenario "typeof s" return "string" without s being string.

is there reason === operator instead of ==?

reason being, want check types in switch statement, afaik, switch statement uses loose comparison operator. since i'm looking known types , don't need check undefined, should fine, right?


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -