0

In my application, I have the following code.

if (values && (values.cardNumber !== undefined)) {

But I have seen in some places where it looks something like this.

if (values && typeof (values.cardNumber !== 'undefined')) {

Which is the better and more secure approach to check if something is undefined??

Shashika Virajh
  • 8,497
  • 17
  • 59
  • 103
  • 3
    You should keep it the way it is. `typeof` offers no advantage in practice. (Also, that would be the wrong way to use it.) Relevant answer if you’re looking for a lot of detail (ignore the accepted one): https://stackoverflow.com/questions/27509/detecting-an-undefined-object-property/22053469#22053469 – Ry- Jul 05 '19 at 05:54
  • Thanks RY for the info – Shashika Virajh Jul 05 '19 at 10:23

0 Answers0