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…


This content originally appeared on DEV Community and was authored by Arya Krishna

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.


This content originally appeared on DEV Community and was authored by Arya Krishna


Print Share Comment Cite Upload Translate Updates
APA

Arya Krishna | Sciencx (2022-05-02T01:01:10+00:00) Svelte: Labeled Statements. Retrieved from https://www.scien.cx/2022/05/02/svelte-labeled-statements/

MLA
" » Svelte: Labeled Statements." Arya Krishna | Sciencx - Monday May 2, 2022, https://www.scien.cx/2022/05/02/svelte-labeled-statements/
HARVARD
Arya Krishna | Sciencx Monday May 2, 2022 » Svelte: Labeled Statements., viewed ,<https://www.scien.cx/2022/05/02/svelte-labeled-statements/>
VANCOUVER
Arya Krishna | Sciencx - » Svelte: Labeled Statements. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/05/02/svelte-labeled-statements/
CHICAGO
" » Svelte: Labeled Statements." Arya Krishna | Sciencx - Accessed . https://www.scien.cx/2022/05/02/svelte-labeled-statements/
IEEE
" » Svelte: Labeled Statements." Arya Krishna | Sciencx [Online]. Available: https://www.scien.cx/2022/05/02/svelte-labeled-statements/. [Accessed: ]
rf:citation
» Svelte: Labeled Statements | Arya Krishna | Sciencx | https://www.scien.cx/2022/05/02/svelte-labeled-statements/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.