Does JavaScript's typeof function check for null -
does javascripts typeof
expression check null?
var test = {}; console.log(typeof test['test']);//"undefined" var test = null; console.log(typeof test['test']);//typeerror: test null
obviously, why error, if typeof null
object?
edit:
know how avoid type error, , null
has no properties, i'm wondering there explanation behavior of typeof
.
var test = { test: null }; console.log(typeof test['test']);// object
your code throws exception because reading property of null this:
null['test']
Comments
Post a Comment