Inconsistent typeof



  • I would expect the console output of this code to be number : number. But for some reason if I don't initialize the array element it increments it and turns it into a string.

    const var foo = [];
    const var bar = [0];
    
    foo[0]++;
    bar[0]++;
    
    Console.print(typeof foo[0] + " : " + typeof bar[0]);
    


  • If you google "Javascript weirdness", that's just the tip of the iceberg...


Log in to reply
 

3
Online

603
Users

2.4k
Topics

18.5k
Posts