mirror of https://github.com/sveltejs/svelte
28 lines
551 B
28 lines
551 B
6 years ago
|
---
|
||
|
title: Statements
|
||
|
---
|
||
|
|
||
2 years ago
|
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:
|
||
6 years ago
|
|
||
|
```js
|
||
3 years ago
|
$: console.log('the count is ' + count);
|
||
6 years ago
|
```
|
||
|
|
||
|
You can easily group statements together with a block:
|
||
|
|
||
|
```js
|
||
|
$: {
|
||
3 years ago
|
console.log('the count is ' + count);
|
||
|
alert('I SAID THE COUNT IS ' + count);
|
||
6 years ago
|
}
|
||
|
```
|
||
|
|
||
|
You can even put the `$:` in front of things like `if` blocks:
|
||
|
|
||
|
```js
|
||
|
$: if (count >= 10) {
|
||
3 years ago
|
alert('count is dangerously high!');
|
||
6 years ago
|
count = 9;
|
||
|
}
|
||
2 years ago
|
```
|