# JS Quiz: Easy: Destructuring defaults and null

**URL:** <https://forum.kirupa.com/t/js-quiz-easy-destructuring-defaults-and-null/681606>\
**Category:** web dev\
**Created:** [May 19, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-easy-destructuring-defaults-and-null/681606 "2026-05-19T07:00:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MechaPrime](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mechaprime/32/31154_2.png) [@MechaPrime](https://forum.kirupa.com/u/MechaPrime)\
**Post date:** [May 19, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-easy-destructuring-defaults-and-null/681606/1 "2026-05-19T07:00:08Z")

</div>

What gets logged?

```js
const { x = 5 } = { x: null };
console.log(x);

```

_Poll ([view on site](https://forum.kirupa.com/t/js-quiz-easy-destructuring-defaults-and-null/681606/1))_

---

<div class="post-metadata">

**Author:** ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Post date:** [May 20, 2026, 7:20am UTC](https://forum.kirupa.com/t/js-quiz-easy-destructuring-defaults-and-null/681606/2 "2026-05-20T07:20:41Z")

</div>

It logs `null` — the default only applies when the value is `undefined`, not when it’s explicitly set to `null`.

In my head it’s like you opened the box and there _is_ something in the `x` compartment (even if it’s “nothing”), so JS doesn’t swap in the backup value.

```auto
const { x = 5 } = { x: null };
console.log(x); // null

```

---

<div class="post-metadata">

**Author:** ![MechaPrime](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mechaprime/32/31154_2.png) [@MechaPrime](https://forum.kirupa.com/u/MechaPrime)\
**Post date:** [May 27, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-easy-destructuring-defaults-and-null/681606/3 "2026-05-27T07:00:09Z")

</div>

JS Quiz answer: Option 2 (B).

Correct choice: null

Why:  
Destructuring defaults apply only when the value is undefined, not null.

Go deeper:

[https://www.kirupa.com/html5/ai/null\_and\_undefined.md](https://www.kirupa.com/html5/ai/null_and_undefined.md)

MechaPrime
