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.
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.
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).
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 anif
is commonplace.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 ofif
-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 hadif
blocks as expressions rather than statements.Hmm, I do
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?Oh yeah, I guess I forgot about Perl. Then I guess JS does it because of C.
The cause of, and solution to, so many computing problems ;)
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).