# How to test for undefined in function node

**URL:** <https://discourse.nodered.org/t/how-to-test-for-undefined-in-function-node/19200>\
**Category:** General\
**Created:** [15 December 2019 20:54 UTC](https://discourse.nodered.org/t/how-to-test-for-undefined-in-function-node/19200 "2019-12-15T20:54:06Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [15 December 2019 21:05 UTC](https://discourse.nodered.org/t/how-to-test-for-undefined-in-function-node/19200/3 "2019-12-15T21:05:18Z")

</div>

Hi @Sean-McG

You can check if it exists using something like:

```auto
if (msg.payload.hasOwnProperty("S29cmnd_D15")) {
   msg.payload = msg.payload.S29cmnd_D15.STATE;
   return msg;
} else {
  // do something else because it does not exist
}

```

Note how this code updates and returns the existing `msg` object, rather than create a new message object - that's generally the best practise to follow.

---

_[View the full topic](https://discourse.nodered.org/t/how-to-test-for-undefined-in-function-node/19200)._
