Skip to content

Commit 7c6baff

Browse files
committed
add section to doc
1 parent 79063bd commit 7c6baff

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

site/content/docs/02-template-syntax.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,29 @@ The `{@debug ...}` tag offers an alternative to `console.log(...)`. It logs the
453453
The `{@debug}` tag without any arguments will insert a `debugger` statement that gets triggered when *any* state changes, as opposed to the specified variables.
454454

455455

456+
### {@const ...}
457+
458+
```sv
459+
{@const assignment}
460+
```
461+
462+
---
463+
464+
The `{@const ...}` tag defines a local constant.
465+
466+
```sv
467+
<script>
468+
export let boxes;
469+
</script>
470+
471+
{#each boxes as box}
472+
{@const area = box.width * box.height}
473+
{box.width} * {box.height} = {area}
474+
{/each}
475+
```
476+
477+
`{@const}` is only allowed as direct child of `{#each}` block, `{#then}` and `{#catch}` block, `<Component />` and `<svelte:fragment />` element.
478+
456479

457480
### Element directives
458481

0 commit comments

Comments
 (0)