Closures and Callbacks
Callback Branches
Choose which callback to run.
callback-branch
Callbacks can contain choices. Here the callback maps a value to one of two labels.
Callback Branches
callback_branch.js
Replay: real traced execution (multi-file project)
const amount = 6;
const limit = 5;
const labels = [amount].map((value) => value <= limit ? "small:" + value : "large:" + value);
console.log("amount=" + amount);
console.log("label=" + labels[0]);
const amount = 3;
const limit = 5;
const labels = [amount].map((value) => value <= limit ? "small:" + value : "large:" + value);
console.log("amount=" + amount);
console.log("label=" + labels[0]);
const amount = 9;
const limit = 5;
const labels = [amount].map((value) => value <= limit ? "small:" + value : "large:" + value);
console.log("amount=" + amount);
console.log("label=" + labels[0]);
amount ← 6, limit ← 5, labels ← large:6
1const amount→ 6 = 6; //@amount=3, 92const limit→ 5 = 5;3const labels→ large:6 = [amount6].map((value) => value <= limit ? "small:" + value : "large:" + value);45console.log("amount=" + amount6);6console.log("label=" + labels[0]large:6);outputamount=6 label=large:6
amount ← 3, limit ← 5, labels ← small:3
1const amount→ 3 = 3;2const limit→ 5 = 5;3const labels→ small:3 = [amount3].map((value) => value <= limit ? "small:" + value : "large:" + value);45console.log("amount=" + amount3);6console.log("label=" + labels[0]small:3);outputamount=3 label=small:3
amount ← 9, limit ← 5, labels ← large:9
1const amount→ 9 = 9;2const limit→ 5 = 5;3const labels→ large:9 = [amount9].map((value) => value <= limit ? "small:" + value : "large:" + value);45console.log("amount=" + amount9);6console.log("label=" + labels[0]large:9);outputamount=9 label=large:9