How to use let declarations as expressions?
问题 I want to use let expressions, but the following code doesn't work: true ? (let x=1, let y=2, x+y) : (let x=3, let y=4, x-y); // SyntaxError How am I supposed to do this? 回答1: Unfortunately, Javascript lacks lisp-style let expressions. However, since there are default parameters and arrow functions we can mimic them: const let_ = f => f(); console.log( true ? let_((x = 1, y = 2) => x + y) : let_((x = 3, y = 4) => x - y) // 3 ); To be honest, this is a bit tedious and the code is pretty