You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/documentation/tutorial/02-reactivity/03-reactive-statements/text.md

28 lines
551 B

---
title: 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:
```js
$: console.log('the count is ' + count);
```
You can easily group statements together with a block:
```js
$: {
console.log('the count is ' + count);
alert('I SAID THE COUNT IS ' + count);
}
```
You can even put the `$:` in front of things like `if` blocks:
```js
$: if (count >= 10) {
alert('count is dangerously high!');
count = 9;
}
```