25 February 2022
Svelte is a JavaScript framework that is used to build web applications.
These are the primary differences between Svelte and the “big three” (React, Angular, and Vue):
To try Svelte online, you can go to their website, specifically to the REPL page:
You will see two panes on that page. The left pane is what you would write inside a .svelte file. The right pane is what the result would look like.
Setup instructions:
To create a new project, run the following commands:
npx degit sveltejs/template my-svelte-project
cd my-svelte-project
npm install
npm run dev
<script>
let greeting = 'World';
</script>
<div>Hello {greeting}</div>
<script>
let products = [
{
id: 1,
name: 'Product A'
},
{
id: 2,
name: 'Product B'
}
];
</script>
<ul>
{#each products as product}
<li>{product.id}: {product.name}</li>
{/each}
</ul>
<script>
let number = 42;
</script>
{#if number > 10 }
<div>The number is big.</div>
{:else}
<div>The number is small.</div>
{/if}
<script>
function clickHandler() {
alert('button was clicked')
}
</script>
<button on:click={clickHandler}>My Button</button>
<script>
let name = 'John';
</script>
<input bind:value={name} />