0

What is wrong on my code?

let x = ['hello',1]
let y = [2]
let z = {x:"hello",y:2}
console.log("type of x:",typeof x) // expected array!
console.log("type of y:",typeof y) // expected array!
console.log("type of z:",typeof z) // expected object, ok

Result:

type of x: object
type of y: object
type of z: object
Peter Krauss
  • 13,174
  • 24
  • 167
  • 304

1 Answers1

2

Because JavaScript arrays are objects.

You can check whether a value is an array using the Array.isArray() function.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308