# Next.js issue-tracker: typeof params.id !== "number"?

**URL:** <https://forum.codewithmosh.com/t/next-js-issue-tracker-typeof-params-id-number/23011>\
**Category:** Next.js\
**Created:** [October 13, 2023, 9:46pm UTC](https://forum.codewithmosh.com/t/next-js-issue-tracker-typeof-params-id-number/23011 "2023-10-13T21:46:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Programmist](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/programmist/32/7006_2.png) [@Programmist](https://forum.codewithmosh.com/u/Programmist)\
**Post date:** [October 13, 2023, 9:46pm UTC](https://forum.codewithmosh.com/t/next-js-issue-tracker-typeof-params-id-number/23011/1 "2023-10-13T21:46:45Z")

</div>

At the end of the **Showing Issue Details** lesson (in the **Viewing Issues** section of Next.js part 2) Mosh mentions adding this line of code to render a 404 page if the URI path contains a non-numeric `id` string (e.g. `/issues/abc`).

```js
if (typeof params.id !== "number") notFound();

```

Perhaps I’m missing something (totally plausible). If so, please help me understand because I can’t see how this would work. In all cases where `params.id` is a string primitive, `typeof params.id` results in `"string"`, so the suggested expression should always return `true` and render a 404 page for every issue, even valid numeric IDs. I also tested it and could not get it to work the way the lesson implies.

This wasn’t a surprising result since the `typeof` of a string primitive always results in `"string"`, even for numeric strings. And since we’re using a triple-not-equals there’s no type coercion happening (though, even double-equals operators don’t coerce numeric strings to numbers).

My solution is to parse the string and then test if the result is `NaN`.

```js
if (Number.isNaN(parseInt(id))) notFound();

```

If you’re wondering why I checked for `NaN` rather than using:

```js
typeof parseInt(id) !== "number" // won't work!

```

it’s because `typeof NaN` results in `"number"`. That’s right: `NaN` (which stands for **Not A Number**!) is…a number. 😂

> By the way, if you haven’t seen the classic short talk [“WAT” by Gary Bernhardt](https://www.destroyallsoftware.com/talks/wat) (about 4 mins), check it out. It’s hilarious and may inspire you to read parts of the [ECMAScript spec](https://tc39.es/ecma262/) related to equality and type coercion.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![ekha](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@ekha](https://forum.codewithmosh.com/u/ekha)\
**Post date:** [January 14, 2025, 12:02am UTC](https://forum.codewithmosh.com/t/next-js-issue-tracker-typeof-params-id-number/23011/2 "2025-01-14T00:02:59Z")

</div>

I have used the code like this:  
`if (isNaN(Number(params.id))) notFound();`

---

<div class="post-metadata">

**Author:** ![Programmist](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/programmist/32/7006_2.png) [@Programmist](https://forum.codewithmosh.com/u/Programmist)\
**Post date:** [January 14, 2025, 11:49pm UTC](https://forum.codewithmosh.com/t/next-js-issue-tracker-typeof-params-id-number/23011/4 "2025-01-14T23:49:39Z")

</div>

That will work, but the `Number()` function is redundant in this case since the `isNaN` function already does type conversion before checking if the value passed to it is `NaN`.

I should also mention that the `Number.isNaN` function does **not** do type conversion, but only checks if the value is `NaN`.
