Statements

We’re not limited to declaring reactive values — we can also run arbitrary statements reactively. For example, we can log the value of count whenever it changes:

  1. $: console.log(`the count is ${count}`);

You can easily group statements together with a block:

  1. $: {
  2. console.log(`the count is ${count}`);
  3. alert(`I SAID THE COUNT IS ${count}`);
  4. }

You can even put the $: in front of things like if blocks:

  1. $: if (count >= 10) {
  2. alert(`count is dangerously high!`);
  3. count = 9;
  4. }