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.
Adding a test for
undefineddoesn'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 thetypeofoperator, where it evaluates to"undefined".The
typeofoperator 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.