1. 2

  2. 3

    Since JavaScript was influenced by Scheme, I’m surprised that it doesn’t have an if expression. That seems like a serious omission. I primarily program in Racket and using the result of an if is commonplace.

    1. 3

      What JavaScript took from Scheme were closures, and not much else. The syntax of JS was inspired by C, so if including if-as-statement instead of if-as-expression was a conscious choice it was presumably made for familarity, since that’s how C does it and there were no mainstream languages at the time that had if blocks as expressions rather than statements.

      1. 3

        Hmm, I do

        $foo = $bar if $baz;

        all the time in Perl (unless I want to test the inverse, in which case I use unless). Does this count as an if-expression?

        1. 3

          Oh yeah, I guess I forgot about Perl. Then I guess JS does it because of C.

          1. 2


            The cause of, and solution to, so many computing problems ;)

        2. 2

          Funnily enough, the Atari 2600 BASIC had if expressions (it’s also an IDE for a machine with 4K of ROM and 128 bytes of memory—quite impressive even if the results are lackluster).