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
 

6
Online

882
Users

3.2k
Topics

26.7k
Posts