# Problem with typeof

**URL:** <https://forum.freecodecamp.org/t/problem-with-typeof/142645>\
**Category:** General\
**Created:** [August 19, 2017, 10:47am UTC](https://forum.freecodecamp.org/t/problem-with-typeof/142645 "2017-08-19T10:47:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Milena0](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/milena0/32/90805_2.png) [@Milena0](https://forum.freecodecamp.org/u/Milena0)\
**Post date:** [August 19, 2017, 10:47am UTC](https://forum.freecodecamp.org/t/problem-with-typeof/142645/1 "2017-08-19T10:47:02Z")

</div>

function isArray(val) {  
return typeof val === ‘array’;  
}

I have warning ‘invalid type comparison’ how to fix it? I try replace ‘array’ with Array but not sure about this solution.

---

<div class="post-metadata">

**Author:** ![ppc](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ppc/32/63349_2.png) [@ppc](https://forum.freecodecamp.org/u/ppc)\
**Post date:** [August 19, 2017, 12:20pm UTC](https://forum.freecodecamp.org/t/problem-with-typeof/142645/3 "2017-08-19T12:20:53Z")

</div>

there is no “array” type in javascript - arrays have type “object”

use `Array.isArray` to check for arrays

```javascript
const a=[2,4,6]
const b={0:2, 1:4, 2:6, length:3}
typeof a // "object"
Array.isArray(a) // true
typeof b // "object"
Array.isArray(b) // false

```

> **[typeof](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)**
>
> The typeof operator returns a string indicating the type of the unevaluated operand.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:42pm UTC](https://forum.freecodecamp.org/t/problem-with-typeof/142645/4 "2021-01-17T20:42:03Z")

</div>

Closed on January 17, 2021, 8:42pm UTC


