{
    "componentChunkName": "component---src-templates-post-js",
    "path": "/learning-sveltejs-over-the-weekend/",
    "result": {"data":{"markdownRemark":{"html":"<p><a href=\"https://www.youtube.com/user/vibbbbbba?sub_confirmation=1\"><strong>Subscribe On YouTube</strong></a></p>\n<p>The front-end development world is changing very fast — new technologies and frameworks are being released constantly and sometimes it’s hard to keep the overview.</p>\n<p>Svelte (<a href=\"https://svelte.dev/\">https://svelte.dev/</a>) brings a new approach to JavaScript-based web development: Instead of doing the bulk of the work in the browser (client-side), Svelte shifts that work to a compiler step which is done during development time. This means that no framework code needs to be delivered to the client. Instead Svelte is able to produce highly optimised plain JavaScript code which can be directly interpreted by the browser. No need of loading additional libraries and code to be able to run the web application.</p>\n<p>This approach makes Svelte web applications very fast and efficient. In the tutorial you’ll learn the Svelte basics. We’ll go through every step which is needed to build your own Svelte web application from start to finish.</p>\n<p>If you haven’t heart about Svelte yet, that’s the perfect tutorial to get started … Let’s get into it!</p>\n<h1 id=\"prerequisites\" style=\"position:relative;\"><a href=\"#prerequisites\" aria-label=\"prerequisites permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Prerequisites</h1>\n<p>Before getting into Svelte and creating the first project we need to make sure that Node.js (and the corresponding Node.js package manager NPM) is installed on the system.</p>\n<p>Installing Node.js is very easy. You just need to go to the Node.js website <a href=\"https://nodejs.org/en/\">https://nodejs.org/en/</a>:</p>\n<p><img src=\"https://miro.medium.com/max/1400/0*PC93ttycxqD77iXk.png\" alt=\"\"></p>\n<p>Download the installer for the current version for your platform. Execute the installer and follow the instructions. The installer will guide you through the steps needed to setup Node.js and NPM.</p>\n<p>Furthermore you need to choose a code editor. The recommendation is to use Visual Studio Code (<a href=\"https://code.visualstudio.com/\">https://code.visualstudio.com/</a>):</p>\n<p><img src=\"https://miro.medium.com/max/1400/0*Lh7P49qa3HnsT9xL.png\" alt=\"\"></p>\n<p>You can download and use Visual Studio Code for free. Furthermore you’re able to install the Visual Studio Code Svelte plugin which helps you with IntelliSense and syntax highlighting:</p>\n<h1 id=\"creating-your-first-svelte-project\" style=\"position:relative;\"><a href=\"#creating-your-first-svelte-project\" aria-label=\"creating your first svelte project permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Creating Your First Svelte Project</h1>\n<p>Now we’re ready to create our first Svelte project from scratch. Creating a new project is very easy, open a new terminal and execute the following command:</p>\n<p><code class=\"language-text\">$ npx degit sveltejs/template my-first-svelte-project</code></p>\n<p>This command creates a new project folder <em>my-first-svelte-project</em> and downloads the svelte default project template into that folder. Next, change into the newly created project folder:</p>\n<p><code class=\"language-text\">$ cd my-first-svelte-project</code></p>\n<p>Before running the project we need to make sure that all needed development dependencies are being installed. Therefore execute:</p>\n<p><code class=\"language-text\">$ npm install</code></p>\n<p>This command makes sure that all packages listed in the <em>devDependencies</em> in <em>package.json</em> are being installed into the <em>node_modules</em> folder. In the following listing you can see the <em>devDependencies</em> section of <em>package.json</em>:</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\">\ndevDependencies\"<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>  \n    <span class=\"token property\">\"npm-run-all\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"^4.1.5\"</span><span class=\"token punctuation\">,</span>  \n    <span class=\"token property\">\"rollup\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"^1.10.1\"</span><span class=\"token punctuation\">,</span>  \n    <span class=\"token property\">\"rollup-plugin-commonjs\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"^9.3.4\"</span><span class=\"token punctuation\">,</span>  \n    <span class=\"token property\">\"rollup-plugin-livereload\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"^1.0.0\"</span><span class=\"token punctuation\">,</span>  \n    <span class=\"token property\">\"rollup-plugin-node-resolve\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"^4.2.3\"</span><span class=\"token punctuation\">,</span>  \n    <span class=\"token property\">\"rollup-plugin-svelte\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"^5.0.3\"</span><span class=\"token punctuation\">,</span>  \n    <span class=\"token property\">\"rollup-plugin-terser\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"^4.0.4\"</span><span class=\"token punctuation\">,</span>  \n    <span class=\"token property\">\"sirv-cli\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"^0.4.0\"</span><span class=\"token punctuation\">,</span>  \n    <span class=\"token property\">\"svelte\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"^3.0.0\"</span>  \n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span></code></pre></div>\n<p>The fact that there is only a <em>devDependencies</em> and no <em>dependencies</em> section is special about Svelte. Because Svelte is working as a compiler everything what is needed is processed and translated into plain JavaScript code at development time. For that reason no further dependencies are needed when running the application.</p>\n<p>Next we’re ready to start the development web server by using the following command:</p>\n<p><code class=\"language-text\">$ npm run dev</code></p>\n<p>Having hit return you should be able to see an output similar to what you can see in the following screenshot:</p>\n<p><img src=\"https://miro.medium.com/max/1400/0*L1qqUT6NtdBCrmt-.png\" alt=\"\"></p>\n<p>Here you can see that the application is now running on port 5000 and the web server is listing for changes with live reloading enabled. Accessing <a href=\"http://localhost:5000\">http://localhost:5000</a> in the browser will lead to the following result:</p>\n<p><img src=\"https://miro.medium.com/max/1400/0*mAgsFhywVNojbXYG.png\" alt=\"\"></p>\n<h1 id=\"project-structure\" style=\"position:relative;\"><a href=\"#project-structure\" aria-label=\"project structure permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Project Structure</h1>\n<p>Now that we have a running first Svelte project let’s take a closer look at the project structure:</p>\n<p><img src=\"https://miro.medium.com/max/1100/0*KF_0WxMEIhplore-.png\" alt=\"\"></p>\n<p>First we can see that a <em>node_modules</em> folder is included. This folder is containing all packages which have been listed in the <em>devDependencies</em> section in <em>package.json</em>.</p>\n<p>The folder <em>public</em> is containing the output of the compilation which is performed by Svelte. A <em>bundle.js</em> and <em>bundle.css</em> file is available containing the optimized JavaScript and CSS code. You’ll also find the file index.html file in which the JavaScript code of <em>bundle.js</em> is included:</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token doctype\"><span class=\"token punctuation\">&lt;!</span><span class=\"token name\">doctype</span> <span class=\"token name\">html</span><span class=\"token punctuation\">></span></span>  \n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>html</span><span class=\"token punctuation\">></span></span>  \n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>head</span><span class=\"token punctuation\">></span></span>  \n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>meta</span> <span class=\"token attr-name\">charset</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">'</span>utf8<span class=\"token punctuation\">'</span></span><span class=\"token punctuation\">></span></span>  \n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>meta</span> <span class=\"token attr-name\">name</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">'</span>viewport<span class=\"token punctuation\">'</span></span> <span class=\"token attr-name\">content</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">'</span>width=device-width<span class=\"token punctuation\">'</span></span><span class=\"token punctuation\">></span></span>  \n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>title</span><span class=\"token punctuation\">></span></span>Svelte app<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>title</span><span class=\"token punctuation\">></span></span>  \n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>link</span> <span class=\"token attr-name\">rel</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">'</span>icon<span class=\"token punctuation\">'</span></span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">'</span>image/png<span class=\"token punctuation\">'</span></span> <span class=\"token attr-name\">href</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">'</span>favicon.png<span class=\"token punctuation\">'</span></span><span class=\"token punctuation\">></span></span>  \n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>link</span> <span class=\"token attr-name\">rel</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">'</span>stylesheet<span class=\"token punctuation\">'</span></span> <span class=\"token attr-name\">href</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">'</span>global.css<span class=\"token punctuation\">'</span></span><span class=\"token punctuation\">></span></span>  \n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>link</span> <span class=\"token attr-name\">rel</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">'</span>stylesheet<span class=\"token punctuation\">'</span></span> <span class=\"token attr-name\">href</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">'</span>bundle.css<span class=\"token punctuation\">'</span></span><span class=\"token punctuation\">></span></span>  \n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>head</span><span class=\"token punctuation\">></span></span>  \n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>body</span><span class=\"token punctuation\">></span></span>  \n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span> <span class=\"token attr-name\">src</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">'</span>bundle.js<span class=\"token punctuation\">'</span></span><span class=\"token punctuation\">></span></span><span class=\"token script\"></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span>  \n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>body</span><span class=\"token punctuation\">></span></span>  \n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>html</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<p>The <em>src</em> folder is the place which you will use to store all your custom Svelte code into. Furthermore the folder contains by default the files <em>main.js</em> and <em>App.svelte</em>. Let’s take a look into those fildes:</p>\n<p>Inside of <em>main.js</em> you should find the following lines of code:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">\n<span class=\"token keyword\">import</span> App <span class=\"token keyword\">from</span> <span class=\"token string\">'./App.svelte'</span><span class=\"token punctuation\">;</span><span class=\"token keyword\">const</span> app <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>  \n    target<span class=\"token operator\">:</span> document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">,</span>  \n    props<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>  \n        name<span class=\"token operator\">:</span> <span class=\"token string\">'world'</span>  \n    <span class=\"token punctuation\">}</span>  \n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> app<span class=\"token punctuation\">;</span></code></pre></div>\n<p>This is the starting point of the Svelte application. The main application component is imported from <em>App.svelte</em> and a new instance of App is created. A configuration object is passed into the constructor call containing the following two properties:</p>\n<ul>\n<li>target: is set to <em>document.body</em> to specify that the HTML output which is generted by App component should be inserted into the document body.</li>\n<li>props: an object is assigned containing the properties which should be passed into App component.</li>\n</ul>\n<p>Now let’s take a look at the code which is available in <em>App.svelte</em>:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>  \n    <span class=\"token keyword\">export</span> <span class=\"token keyword\">let</span> name<span class=\"token punctuation\">;</span>  \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span><span class=\"token operator\">&lt;</span>style<span class=\"token operator\">></span>  \n    h1 <span class=\"token punctuation\">{</span>  \n        color<span class=\"token operator\">:</span> purple<span class=\"token punctuation\">;</span>  \n    <span class=\"token punctuation\">}</span>  \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>style<span class=\"token operator\">></span><span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello <span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span></code></pre></div>\n<p>This is a typical implementation of a Svelte component which is devided into three blocks:</p>\n<ul>\n<li>script section: This section is containing the JavaScript code of the component. In this case the name variable is defined as a property (by using the export keyword).</li>\n<li>style section: The style section is containing CSS code which is scoped to the component.</li>\n<li>template section: The template section is containg the markup code (and Svelte specific enhancements) which are used to generate the HTML output of the component.</li>\n</ul>\n<h1 id=\"creating-your-first-svelte-component\" style=\"position:relative;\"><a href=\"#creating-your-first-svelte-component\" aria-label=\"creating your first svelte component permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Creating Your First Svelte Component</h1>\n<p>Now that you have a first overview of the intial project structure we’re ready to add a further custom Svelte component to the project by creating a new file <em>src/Greeting.svelte</em> and inserting the following line of code:</p>\n<h2>Hello World!</h2>\n<p>This is a just a very simple component conisting of only one line of template code outputting the text “Hello World!\" as a headline.</p>\n<p>To make use of that custom component and make the output visible in the browser we need to include the component in the main application component App component:</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span><span class=\"token punctuation\">></span></span><span class=\"token script\"><span class=\"token language-javascript\">  \n    <span class=\"token keyword\">import</span> Greeting <span class=\"token keyword\">from</span> <span class=\"token string\">'./Greeting.svelte'</span><span class=\"token punctuation\">;</span>    <span class=\"token keyword\">export</span> <span class=\"token keyword\">let</span> name<span class=\"token punctuation\">;</span>  \n</span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>style</span><span class=\"token punctuation\">></span></span><span class=\"token style\"><span class=\"token language-css\">  \n    <span class=\"token selector\">h1</span> <span class=\"token punctuation\">{</span>  \n        <span class=\"token property\">color</span><span class=\"token punctuation\">:</span> purple<span class=\"token punctuation\">;</span>  \n    <span class=\"token punctuation\">}</span>  \n</span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>style</span><span class=\"token punctuation\">></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span><span class=\"token punctuation\">></span></span>Hello {name}!<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>Greeting</span><span class=\"token punctuation\">/></span></span>\n</code></pre></div>\n<p>First the corresponding import statement needs to be added in the script section and second the HTML element <Greeting /> needs to be inserted into the template code of App component.</p>\n<p>By using that HTML element we’re making sure that the HTML output of Greeting component is inserted into the output of App component.</p>\n<h1 id=\"styling\" style=\"position:relative;\"><a href=\"#styling\" aria-label=\"styling permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Styling</h1>\n<p>Adding CSS code to a Svelte component is extremely easy. As seen before the only thing which is needed is a script block with the corresponding CSS code inside. E.g. change the content of Greeting.svelte to the following to add some additional styling to the output:</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>style</span><span class=\"token punctuation\">></span></span><span class=\"token style\"><span class=\"token language-css\">  \n    <span class=\"token selector\">h2</span> <span class=\"token punctuation\">{</span>  \n        <span class=\"token property\">color</span><span class=\"token punctuation\">:</span> purple<span class=\"token punctuation\">;</span>  \n        <span class=\"token property\">font-family</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Comic Sans MS'</span><span class=\"token punctuation\">;</span>  \n        <span class=\"token property\">font-size</span><span class=\"token punctuation\">:</span> 2em<span class=\"token punctuation\">;</span>  \n    <span class=\"token punctuation\">}</span>  \n</span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>style</span><span class=\"token punctuation\">></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h2</span><span class=\"token punctuation\">></span></span>Hello World!<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h2</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<h1 id=\"properties--computed-properties\" style=\"position:relative;\"><a href=\"#properties--computed-properties\" aria-label=\"properties  computed properties permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Properties &#x26; Computed Properties</h1>\n<p>Each component is able to receive data through components. To add components to a component you just have to add variables to the script section and declare those variables by using the export keyword. E.g. add the following two properties to <em>Greeting</em> component:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>  \n    <span class=\"token keyword\">export</span> <span class=\"token keyword\">let</span> first_name<span class=\"token punctuation\">;</span>  \n    <span class=\"token keyword\">export</span> <span class=\"token keyword\">let</span> last_name<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span></code></pre></div>\n<p>Also change the template code to:</p>\n<h2>Hello {first_name} {last_name}</h2>\n<p>With these changes in place you’re ready pass in values when the component is being used in <em>App.svelte:</em></p>\n<Greeting first_name=\"Steve\" last_name=\"Smith\"/>\n<p>Furthermore Svelte is supporting computed properties as well. In the following you can see that a computed property <em>name</em> is added:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">\n<span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>  \n    <span class=\"token keyword\">export</span> <span class=\"token keyword\">let</span> first_name<span class=\"token punctuation\">;</span>  \n    <span class=\"token keyword\">export</span> <span class=\"token keyword\">let</span> last_name<span class=\"token punctuation\">;</span>    $<span class=\"token operator\">:</span> name <span class=\"token operator\">=</span> first_name <span class=\"token operator\">+</span> <span class=\"token string\">\" \"</span> <span class=\"token operator\">+</span> last_name<span class=\"token punctuation\">;</span>   \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span><span class=\"token operator\">&lt;</span>style<span class=\"token operator\">></span>  \n    h2 <span class=\"token punctuation\">{</span>   \n        color<span class=\"token operator\">:</span> purple<span class=\"token punctuation\">;</span>  \n        font<span class=\"token operator\">-</span>family<span class=\"token operator\">:</span> <span class=\"token string\">'Comic Sans MS'</span><span class=\"token punctuation\">;</span>  \n        font<span class=\"token operator\">-</span>size<span class=\"token operator\">:</span> <span class=\"token number\">2</span>em<span class=\"token punctuation\">;</span>  \n    <span class=\"token punctuation\">}</span>  \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>style<span class=\"token operator\">></span><span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>Hello <span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span>\n</code></pre></div>\n<p>Computed properties are fully reactive. That means if some of the depending variables are changing (<em>first_name</em> or <em>last_name</em>) the value for name is updated automatically.</p>\n<h1 id=\"logic\" style=\"position:relative;\"><a href=\"#logic\" aria-label=\"logic permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Logic</h1>\n<p>In Svelte it’s possible to add logic to the template directly. Let’s see what that means:</p>\n<h1 id=\"if-block\" style=\"position:relative;\"><a href=\"#if-block\" aria-label=\"if block permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>If-Block</h1>\n<p>In the following you can see a new component which is created in <em>src/LogIn.svelte</em>:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>  \n    <span class=\"token keyword\">let</span> user <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> loggedIn<span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>    <span class=\"token keyword\">function</span> <span class=\"token function\">toggle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>  \n        user<span class=\"token punctuation\">.</span>loggedIn <span class=\"token operator\">=</span> <span class=\"token operator\">!</span>user<span class=\"token punctuation\">.</span>loggedIn<span class=\"token punctuation\">;</span>  \n    <span class=\"token punctuation\">}</span>  \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>#<span class=\"token keyword\">if</span> user<span class=\"token punctuation\">.</span>loggedIn<span class=\"token punctuation\">}</span>  \n    <span class=\"token operator\">&lt;</span>button on<span class=\"token operator\">:</span>click<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>toggle<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>  \n        Log out  \n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>  \n<span class=\"token punctuation\">{</span><span class=\"token operator\">/</span><span class=\"token keyword\">if</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">{</span>#<span class=\"token keyword\">if</span> <span class=\"token operator\">!</span>user<span class=\"token punctuation\">.</span>loggedIn<span class=\"token punctuation\">}</span>  \n    <span class=\"token operator\">&lt;</span>button on<span class=\"token operator\">:</span>click<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>toggle<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>  \n        Log <span class=\"token keyword\">in</span>  \n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>  \n<span class=\"token punctuation\">{</span><span class=\"token operator\">/</span><span class=\"token keyword\">if</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>This component outputs a simple button. By clicking on the button the state changes from logged in to logged out. Depending on the state the button is displayed either with the text “Log out\" (if the state is logged in) or “Log in\" (if the state is logged out.</p>\n<p>The state is tracked by a variable named user which is a boolean property of loggedIn. Depending on the value of that property the template is outputting the button with the corresponding text. This is controlled by using the <code class=\"language-text\">{#if [condititon]} ... {/if}</code> syntax in the template code.</p>\n<p>In order to see the output of the LogIn component do not forget to include the corresponding import statement in <em>src/App.svelte</em>:</p>\n<p>import LogIn from './LogIn.svelte';</p>\n<p>And add the <code class=\"language-text\">&lt;LogIn /></code> HTML element to the template code:</p>\n<LogIn />\n<h1 id=\"if-else-block\" style=\"position:relative;\"><a href=\"#if-else-block\" aria-label=\"if else block permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>If-Else-Block</h1>\n<p>The previous example uses two <code class=\"language-text\">{#if [condititon]} ... {/if}</code> blocks to control the output of the buttons. This is fully working and you're able to change between the two states by clicking on the button. However the code can be changed to only contain one <code class=\"language-text\">{#if [condititon]} ... {/if}</code> block by also addding an <code class=\"language-text\">{:else}</code> branch:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>  \n    <span class=\"token keyword\">let</span> user <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> loggedIn<span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>    <span class=\"token keyword\">function</span> <span class=\"token function\">toggle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>  \n        user<span class=\"token punctuation\">.</span>loggedIn <span class=\"token operator\">=</span> <span class=\"token operator\">!</span>user<span class=\"token punctuation\">.</span>loggedIn<span class=\"token punctuation\">;</span>  \n    <span class=\"token punctuation\">}</span>  \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>#<span class=\"token keyword\">if</span> user<span class=\"token punctuation\">.</span>loggedIn<span class=\"token punctuation\">}</span>  \n    <span class=\"token operator\">&lt;</span>button on<span class=\"token operator\">:</span>click<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>toggle<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>  \n        Log out  \n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>  \n<span class=\"token punctuation\">{</span><span class=\"token operator\">:</span><span class=\"token keyword\">else</span><span class=\"token punctuation\">}</span>  \n    <span class=\"token operator\">&lt;</span>button on<span class=\"token operator\">:</span>click<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>toggle<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>  \n        Log <span class=\"token keyword\">in</span>  \n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>  \n<span class=\"token punctuation\">{</span><span class=\"token operator\">/</span><span class=\"token keyword\">if</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h1 id=\"each-block\" style=\"position:relative;\"><a href=\"#each-block\" aria-label=\"each block permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Each-Block</h1>\n<p>Svelte gives you access to another template element which makes it easy to generate output for a list. Let’s take a look into the following example which is inserted into a new file <em>FrameworkList.svelte</em>:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>  \n    <span class=\"token keyword\">let</span> frameworks <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>  \n        <span class=\"token punctuation\">{</span>id<span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> name<span class=\"token operator\">:</span> <span class=\"token string\">'Svelte'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>  \n        <span class=\"token punctuation\">{</span>id<span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> name<span class=\"token operator\">:</span> <span class=\"token string\">'Angular'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>  \n        <span class=\"token punctuation\">{</span>id<span class=\"token operator\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> name<span class=\"token operator\">:</span> <span class=\"token string\">'React'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>  \n        <span class=\"token punctuation\">{</span>id<span class=\"token operator\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> name<span class=\"token operator\">:</span> <span class=\"token string\">'Vue'</span><span class=\"token punctuation\">}</span>  \n    <span class=\"token punctuation\">]</span>  \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span><span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>List <span class=\"token keyword\">of</span> Frameworks<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span>  \n    <span class=\"token punctuation\">{</span>#each frameworks <span class=\"token keyword\">as</span> <span class=\"token punctuation\">{</span>id<span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>  \n        <span class=\"token operator\">&lt;</span>li<span class=\"token operator\">></span>  \n            <span class=\"token punctuation\">{</span>id<span class=\"token punctuation\">}</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span>  \n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>  \n    <span class=\"token punctuation\">{</span><span class=\"token operator\">/</span>each<span class=\"token punctuation\">}</span>  \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span></code></pre></div>\n<p>First of all an array is created and assigned to the <em>frameworks</em> variable. Each array element is an object consisting of two properties.</p>\n<p>To output the data an {#each} … {/each} block is used. For each element a <li> element is added to the HTML output.</p>\n<p>To include this new FrameworkList component in <em>App.svelte</em> add the following <em>import</em> statement:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">import</span> FrameworkList <span class=\"token keyword\">from</span> <span class=\"token string\">'./FrameworkList.svelte'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>And don’t forget to add the corresponding HTML element to the template code as well:</p>\n<h1 id=\"events\" style=\"position:relative;\"><a href=\"#events\" aria-label=\"events permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Events</h1>\n<p>Next, let’s take a look at events in Svelte. We’ve already seen a first example in the previous examples when responding to the click event of a button:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>button on<span class=\"token operator\">:</span>click<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>toggle<span class=\"token punctuation\">}</span><span class=\"token operator\">></span></code></pre></div>\n<p>By using that line of code we’ve connected the toggle function (which needs to be added to the script section of the component) to the click event of the button. Everytime the user clicks on the button the function is called and therefore is able to handle the event.</p>\n<p>Let’s take a look at a second example which is inserted into a new component file <em>EventDemo.svelte</em>:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>  \n    <span class=\"token keyword\">let</span> m <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> x<span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> y<span class=\"token operator\">:</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>    <span class=\"token keyword\">function</span> <span class=\"token function\">handleMousemove</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>  \n        m<span class=\"token punctuation\">.</span>x <span class=\"token operator\">=</span> event<span class=\"token punctuation\">.</span>clientX<span class=\"token punctuation\">;</span>  \n        m<span class=\"token punctuation\">.</span>y <span class=\"token operator\">=</span> event<span class=\"token punctuation\">.</span>clientY<span class=\"token punctuation\">;</span>  \n    <span class=\"token punctuation\">}</span>  \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span><span class=\"token operator\">&lt;</span>style<span class=\"token operator\">></span>  \n    div <span class=\"token punctuation\">{</span>  \n        width<span class=\"token operator\">:</span> <span class=\"token number\">300</span>px<span class=\"token punctuation\">;</span>  \n        height<span class=\"token operator\">:</span> <span class=\"token number\">300</span>px<span class=\"token punctuation\">;</span>  \n        color<span class=\"token operator\">:</span> purple<span class=\"token punctuation\">;</span>  \n        background<span class=\"token operator\">:</span> lightseagreen<span class=\"token punctuation\">;</span>  \n    <span class=\"token punctuation\">}</span>  \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>style<span class=\"token operator\">></span><span class=\"token operator\">&lt;</span>div on<span class=\"token operator\">:</span>mousemove<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>handleMousemove<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>  \n    The mouse position is <span class=\"token punctuation\">{</span>m<span class=\"token punctuation\">.</span>x<span class=\"token punctuation\">}</span> x <span class=\"token punctuation\">{</span>m<span class=\"token punctuation\">.</span>y<span class=\"token punctuation\">}</span>  \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span></code></pre></div>\n<p>Here we’re responding to the mouse move event of a div area by adding the following attribute to the element:</p>\n<p>on:mousemove={handleMousemove}</p>\n<p>The <em>handleMousemove</em> function is registered as the event handler for the mousemove event. Everytime the mouse is moved within the div area the event is triggered and the function is called. The function is then updating the x and y position of the mouse in <em>m.x</em> and <em>m.y</em>.</p>\n<p>To make everything visible add the corresponding import statement in <em>App.svelte</em>:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">import</span> EventDemo <span class=\"token keyword\">from</span> <span class=\"token string\">'./EventDemo.svelte'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>And make sure to include the <code class=\"language-text\">&lt;EventDemo /></code> element in the template code.</p>\n<h1 id=\"bindings\" style=\"position:relative;\"><a href=\"#bindings\" aria-label=\"bindings permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Bindings</h1>\n<p>Last but not least let’s explore bindings in Svelte. Again we’re starting with a simple practical example to understand the concept. In <em>BindingDemo.svelte</em> add the following sample code:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>  \n    <span class=\"token keyword\">let</span> name <span class=\"token operator\">=</span> <span class=\"token string\">\"Sebastian\"</span>  \n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span><span class=\"token operator\">&lt;</span>input bind<span class=\"token operator\">:</span>value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello <span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span></code></pre></div>\n<p>The value of the input element is bound to the variable <em>name</em>. This means that the binding is working two-way. Initially the value of name is displayed in the input element. When the user changed the value of the input element to value of name is updated accordingly.</p>\n<p>In thee following screenshot you can see the complete browser output after all custom Svelte components have been included and added to App component:</p>\n<h1 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h1>\n<p>Compared to web development frameworks and platforms like Angular, React and Vue.js, Svelte introduces a new approach into JavaScript-based web development. By using a compiler approach Svelte makes sure that only highly optimized plain JavaScript, CSS and HTML code is delivered to the client.</p>\n<p>Svelte is very easy to learn. The framework combines the best syntax elements from Angular, React and Vue. The source code is easy to read and therewith you will be able to make quick progress implementing your first Svelte web application. Just give it a try.</p>","excerpt":"Subscribe On YouTube The front-end development world is changing very fast — new technologies and frameworks are being released constantly…","fields":{"slug":"/learning-sveltejs-over-the-weekend/"},"frontmatter":{"title":"learning svelte js quick starter","date":"June 03, 2022","tags":["seveltejs","javascript"],"description":"learning svelte js quick starter"}}},"pageContext":{"slug":"/learning-sveltejs-over-the-weekend/","previous":{"id":"fdeed646-8e02-5f4d-b1e7-20109f4a61db","frontmatter":{"title":"Using React Hooks for Your Forms with Validation","tags":["reactjs","javascript"],"categories":["reactjs","javascript"],"template":"post"},"fields":{"slug":"/using-react-hook-forms-for-validation/"}},"next":{"id":"bae1e11f-5d59-51fa-a942-87e106f2b300","frontmatter":{"title":"learning accessibility standards reactjs","tags":["web-design","reactjs","a11y"],"categories":["a11y","reactjs","web-design"],"template":"post"},"fields":{"slug":"/web-accessibility-a11y-using-reactjs/"}}}},
    "staticQueryHashes": ["352937542"]}