JavaScript insanity

Seriously, what would you think about a language that is weakly typed and uses the same operator for concatenation and addition?

I think it’s insane.

Well, so much for my first encounter with JavaScript. And although I encountered way more problems (most of which were caused by my own stupidity, as usual), the fact that the plus sign (aka +) either adds or concatenates (based possibly on the current mood of the interpreter) struck me as the ultimate wtf.

Luckily, parseInt() comes to save the day. But still, why not rather use some other operator? I don’t really care which… just anything else, mmkay?

4 thoughts on “JavaScript insanity

  1. Perl je super. :)
    Tam nic takoveho neni, ne? Muzes uvest priklad operatoru, ktery ma v perlu vic ruznych funkci? (spojovani retezcu se iirc provadi teckou)

  2. V JS “+” scita cisla a slucuje retezce, nebo je v tom neco vic?

    Obecne se da rict, ze konstrukci ktery maji ruzny vyznam v ruznem kontextu (operandu) je v Perlu spousta. Treba u pole:
    @b = @a # neco jako strcpy(b,a) v C
    $b = @a # neco jako $b=count($a) v PHP

    No a pak me jeste napada, ale to si asi over:
    print “Hanka” + 4 # napise 4
    print “2 Lenky” + 4 # napise 6

  3. Ano, “+” v JS scita cisla i spojuje retezce.

    A k tem konstrukcim, ktere maji ruzny vyznam v ruznem kontextu – to mi vubec nevadi. Mne vadi konstrukce, ktere maji nekolik ruznych vyznamu v jednom kontextu.

    Vyhodnocovani prave strany podle toho co je vlevo, jak to dela perl, je podle me naopak super vec. :)

Comments are closed.