# How to handle the undefined

**URL:** https://discourse.processing.org/t/how-to-handle-the-undefined/10552
**Category:** Beginners
**Created:** [April 23, 2019, 2:19am UTC](https://discourse.processing.org/t/how-to-handle-the-undefined/10552 "2019-04-23T02:19:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Aesahaettr](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@Aesahaettr](https://discourse.processing.org/u/Aesahaettr)
#### Post date: [April 23, 2019, 2:19am UTC](https://discourse.processing.org/t/how-to-handle-the-undefined/10552/1 "2019-04-23T02:19:46Z")

</div>

Hello, I have been strugling with some variables that are the type of undefined. I’ve looked on internet but I found nothing on how to determine if it’s “undefined” like this :

```auto
if (typeof tmp == "undefined") {
    tmp = [0, 0];
    console.log("tmp is undefined");
}

```

Has anyone as a solution to counter this?

---

<div class="post-metadata">

### Author: ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)
#### Post date: [April 23, 2019, 2:36am UTC](https://discourse.processing.org/t/how-to-handle-the-undefined/10552/2 "2019-04-23T02:36:45Z")

</div>

you can just do

```auto
var tmp;
console.log(tmp === undefined);//true
tmp = 'hmm';
console.log(tmp === undefined);//false

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [April 23, 2019, 7:09am UTC](https://discourse.processing.org/t/how-to-handle-the-undefined/10552/3 "2019-04-23T07:09:59Z")

</div>

Both `undefined` & `null` got no members in them: 🕳

> **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
>
> The global undefined property represents the primitive value undefined. It is one of JavaScript's primitive types.

  

> **[null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null)**
>
> The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values.

Therefore, we can’t do anything w/ them but check for their presence. ✔

But b/c both of them are considered “falsy” values we can greatly simplify their check w/ just: 💡

`if (!tmp) tmp = [0, 0];` or `tmp = tmp || [0, 0];`. 😉

Rather than `if (tmp == undefined) tmp = [0, 0];`. 😳

> **[Falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy)**
>
> A falsy value is a value that is considered false when encountered in a Boolean context.

---

<div class="post-metadata">

### Author: ![Aesahaettr](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@Aesahaettr](https://discourse.processing.org/u/Aesahaettr)
#### Post date: [April 23, 2019, 5:37pm UTC](https://discourse.processing.org/t/how-to-handle-the-undefined/10552/4 "2019-04-23T17:37:08Z")

</div>

Thanks a lot, it worked as expected 🙂
