The whatis() function will throw a ReferenceError for variables that have not been declared, unlike the typeof operator that evaluates to "undefined" for undeclared variables.
Adding a test for undefined doesn't still solve the undeclared variable problem. In JavaScript, as much as I know, accessing an undeclared variable will always throw a ReferenceError. The only exception being with the typeof operator, where it evaluates to "undefined".
The typeof operator behaves such that it should never throw an error for any valid JavaScript value used as its operand, including an undeclared variable.
That said, running the modified function you defined above with an undeclared variable will still throw a ReferenceError.
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.
Why not add a test for
undefined
then?Adding a test for
undefined
doesn't still solve the undeclared variable problem. In JavaScript, as much as I know, accessing an undeclared variable will always throw aReferenceError
. The only exception being with thetypeof
operator, where it evaluates to"undefined"
.The
typeof
operator behaves such that it should never throw an error for any valid JavaScript value used as its operand, including an undeclared variable.That said, running the modified function you defined above with an undeclared variable will still throw a
ReferenceError
.