Expected an element called undefined but got empty | JavaScript
15:22 26 Feb 2022

I wrote a simple array where I have a few elements.

After deleting an element, I noticed that it outputted "empty" but I was expecting an undefined datatype.

  • I ran the same code on MDN and got an undefined as a result.

  • I ran the code in different browsers but got "empty" as a result.

When I looked for the type of this element it gave me an undefined as a result.

I was wondering why I got 2 different terms for something where the types are the same?

Thank you in advance!

    // code
    const pizzas = ["Margherita", "Mushroom", "Spinach & Rocket", undefined,"Pineapple & Sweetcorn"]
    delete pizzas[2];
    console.log(pizzas);
    console.log(typeof pizzas[2]);

    // output
    ['Margherita', 'Mushroom', empty, undefined, 'Pineapple & Sweetcorn']
    undefined
javascript arrays