You don't need to do a runtime typeof JavaScript introspection. Indeed, here c is declared. Use typeof only to check if a variable is declared.
typeof
c
if ( c === undefined )
Just works in your example.
You can use typeof to check for global variables. For example :
window === undefined
will throw an exception on nodejs when it will return false on your browser. In this case, yes you should use typeof:
typeof window === "undefined"
You're right, in fact typeof c == undefined won't work at all since typeof returns a string. I've updated.
typeof c == undefined
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You don't need to do a runtime
typeofJavaScript introspection. Indeed, herecis declared. Use typeof only to check if a variable is declared.Just works in your example.
You can use
typeofto check for global variables. For example :will throw an exception on nodejs when it will return false on your browser.
In this case, yes you should use
typeof:You're right, in fact
typeof c == undefinedwon't work at all sincetypeofreturns a string. I've updated.