javascript - Why strict comparison(===) when checking typeof equality? -
this question has answer here:
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
Post a Comment