4 ms·
Expressions `yield` values, statements don't yield values. `square = square(4)` is a statement (a definition to be exact) that associates name `square` with th
by oxff 4y ago
Expressions `yield` values, statements don't yield values.
`square = square(4)` is a statement (a definition to be exact) that associates name `square` with the value `square(4)`.
The name `square` itself, when later used, is an expression, because when you call it, it evaluates to a value `square(4)`.
- amadeuspagel 4y agoFor example, you might have tried writing something like this: foo = if (x < y) { ... ... } Doesn't work because statements don't yield values.
- Akronymus 4y agoThats one of the reason why I REALLY like languages where everything is an expression. let foo = if x < y somevalue else someothervalue in f# for example.
- bern4444 4y agoI also love F#. One of the most interesting languages that I've ever seen. This is certainly another great aspect of it.
- bern4444 4y agoSo are ternaries expressions then too? const x = x < y ? 2 : 3;
- amadeuspagel 4y agoYes, indeed.