DEV Community

Cover image for Svelte: Labeled Statements
Arya Krishna
Arya Krishna

Posted on

2 2

Svelte: Labeled Statements

What is the $: in Svelte?

Any top-level statement (i.e. not inside a block or a function) can be made reactive by prefixing it with the $: JS label syntax.

Label statements can be seen in vanilla JavaScript in conjunction with loops and the break and continue keyword and attached.

What svelte does is it grabs this $: statement and we can add a dynamic calculation based on some other value.
$: uppercaseName = name.toUpperCase();

Here name.toUpperCase is a built in JavaScript Method and upperCaseName is a variable.

Svelte will recalculate the value for us whenever the name changes.

Top comments (0)

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay