a = (b = 'string is truthy'); // b gets string; a gets b, which is a primitive (copy)
a = (b = { c: 'yes' }); // they point to the same object; a === b (not a copy)
(a && b)論理的である(a ? b : a)との乗算のように振る舞う(例えば。!!a * !!b)
(a || b)論理的である(a ? a : b)(例えば。ほかのようにして振る舞います!!a + !!b)
(a = 0, b)a真実である場合、気にしないことを意味し、暗黙的に戻りますb
a = (b = 0) && "nope, but a is 0 and b is 0"; // b is falsey + order of operations
a = (b = "b is this string") && "a gets this string"; // b is truthy + order of ops
JavaScript演算子の優先順位(操作の順序)
コンマ演算子は実際には最も特権の少ない演算子ですが、括弧は最も特権が高い演算子であり、1行の式を作成する場合は括弧が密接に関係していることに注意してください。
最終的には、ハードコードされた値ではなく「サンク」が必要になる場合があります。私にとって、サンクは関数と結果の値(同じ「もの」)の両方です。
const windowInnerHeight = () => 0.8 * window.innerHeight; // a thunk
windowInnerHeight(); // a thunk