# Cannot read property 'map' of undefined

**URL:** https://forum.codewithmosh.com/t/cannot-read-property-map-of-undefined/4752
**Category:** React
**Created:** [May 7, 2021, 9:10pm UTC](https://forum.codewithmosh.com/t/cannot-read-property-map-of-undefined/4752 "2021-05-07T21:10:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sh2021](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sh2021](https://forum.codewithmosh.com/u/sh2021)
#### Post date: [May 7, 2021, 9:10pm UTC](https://forum.codewithmosh.com/t/cannot-read-property-map-of-undefined/4752/1 "2021-05-07T21:10:07Z")

</div>

I’m following Mosh on Pagination,filtering,sorting video 19 and I’m stuck on making the tableHeader.jsx to work.

I followed his codes step by step, but I keep on getting the error:

tableHeader.jsx:23 Uncaught TypeError: Cannot read property ‘map’ of undefined at TableHeader.render (tableHeader.jsx:23)

tableHeader.jsx looks like below:

 ![tableHeader](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/6/63ea027fcb04d36cc79bcc39d0538d1080f62868.png)

I have no idea, what should be fixed, any useful hint is appreciated .

---

<div class="post-metadata">

### Author: ![hlipperjohn](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@hlipperjohn](https://forum.codewithmosh.com/u/hlipperjohn)
#### Post date: [March 15, 2022, 11:53pm UTC](https://forum.codewithmosh.com/t/cannot-read-property-map-of-undefined/4752/2 "2022-03-15T23:53:33Z")

</div>

> [@sh2021](#):
>
> tableHeader.jsx:23 Uncaught TypeError: Cannot read property ‘map’ of undefined at TableHeader.render (tableHeader.jsx:23)

In JavaScript almost everything is an object, null and undefined are exceptions. This error occurs when a property is read or a function is called on an undefined variable. Undefined means that a variable has been declared but has not been assigned a value. In JavaScript, properties and functions can only belong to objects. Since undefined is not an object type, calling a function or a property on such a variable causes the TypeError: [Cannot read property](http://net-informations.com/js/iq/unerror.htm) of undefined.

If you are not sure a variable that will always have some value, the best practice is to check the value of variables for null or undefined before using them. To avoid getting these types of errors, you need to make sure that the variables you are trying to read do have the correct value. This can be done in various ways. You can do if checks before dealing with objects whose values are bound to change:

```auto
if (myVar !== undefined) {
    ...
}

```

Or

```auto
if (typeof(myVar) !== 'undefined') {
    ...
}

```
