3 ms·
> Of course this just JavaScript being a classical imperative language. Not much to do about that. I think you could actually make JavaScript expression based
by nicoburns 6y ago
> Of course this just JavaScript being a classical imperative language. Not much to do about that.
I think you could actually make JavaScript expression based very easily and completely backwards compatibly. Using a statement in expression position currently throws an error. So you would simply be widening the number of allowable programs.
- svieira 6y agoThere is actually a Stage 1 proposal that introduces an expression that does _exactly_ that (because it's not as easy as just making `const x = for(let i of foo) { yield i; };` parse.) https://github.com/tc39/proposal-do-expressions https://github.com/tc39/proposal-do-expressions https://babeljs.io/docs/en/babel-plugin-proposal-do-expressions https://babeljs.io/docs/en/babel-plugin-proposal-do-expressi...
- munificent 6y ago> very easily and completely backwards compatibly. Object literals, blocks, and ASI take that out of the realm of "very easily": var x = if (c) {} else { b: console.log("hi") } If `c` is true, does this give you `null` from executing an empty block, or an empty object? If `c` is `false`, do you get an object with key "b" and value whatever `log()` returns, or is that a block with a labeled statement?
- MHordecki 6y agoThis specific problem was already dealt with during the introduction of arrow functions[1]. It makes sense to keep the same parsing semantics. [1]: https://www.ecma-international.org/ecma-262/11.0/index.html#prod-ConciseBody https://www.ecma-international.org/ecma-262/11.0/index.html#...