<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abde Lazize</title>
    <description>The latest articles on DEV Community by Abde Lazize (@gugocharade).</description>
    <link>https://dev.to/gugocharade</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F359815%2F076d2015-0414-4d67-8dd2-5152e547c3e2.jpg</url>
      <title>DEV Community: Abde Lazize</title>
      <link>https://dev.to/gugocharade</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gugocharade"/>
    <language>en</language>
    <item>
      <title>From Full Stack Freelancer to Micro SaaS Founder: Vibe coding as a Solo Developer</title>
      <dc:creator>Abde Lazize</dc:creator>
      <pubDate>Tue, 29 Apr 2025 16:09:16 +0000</pubDate>
      <link>https://dev.to/gugocharade/from-full-stack-freelancer-to-micro-saas-founder-vibe-coding-as-a-solo-developer-3mdi</link>
      <guid>https://dev.to/gugocharade/from-full-stack-freelancer-to-micro-saas-founder-vibe-coding-as-a-solo-developer-3mdi</guid>
      <description>&lt;p&gt;After four years as a freelance full-stack developer, I decided to join the indie hacking movement and build my own micro SaaS. The result? &lt;a href="https://stickersai.app" rel="noopener noreferrer"&gt;StickersAI&lt;/a&gt; – an AI-powered sticker generator that creates custom stickers from text prompts.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Unexpected Journey
&lt;/h2&gt;

&lt;p&gt;I had spent years comfortable in my code editor, building products for clients. When I decided to create StickersAI, I naively thought that development would be the challenging part. I couldn't have been more wrong.&lt;/p&gt;

&lt;p&gt;While building the product was straightforward for someone with my background, I quickly discovered that creating a SaaS business involves much more than just writing code. Marketing, legal requirements, and tax considerations became my new daily challenges – areas I had never needed to master as a freelancer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tech Stack Snapshot
&lt;/h2&gt;

&lt;p&gt;For those curious about what's powering StickersAI, here's the stack I chose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Frontend/Backend&lt;/em&gt;: Next.js&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Database/Auth&lt;/em&gt;: Supabase&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Styling&lt;/em&gt;: Tailwind CSS with shadcn UI components&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Monitoring&lt;/em&gt;: Sentry for error reporting&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;AI Integration&lt;/em&gt;: OpenAI for prompt enhancement and Replicate for image generation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Leveraging V0 and Cursor AI as my development tools alongside this modern stack dramatically accelerated my workflow as a solo developer. These AI-powered tools handled much of the boilerplate. The combination of Next.js and Supabase proved especially valuable for indie hacking – providing enterprise-level capabilities with minimal DevOps overhead and a scaling path that grows with your user base.&lt;/p&gt;

&lt;h2&gt;
  
  
  Beyond The Tech
&lt;/h2&gt;

&lt;p&gt;What shocked me was how little time I actually spent coding once the initial product was built. Instead, my days became filled with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learning about marketing channels to reach potential users&lt;/li&gt;
&lt;li&gt;Setting up legal documents and understanding compliance requirements&lt;/li&gt;
&lt;li&gt;Figuring out tax implications for digital products sold globally&lt;/li&gt;
&lt;li&gt;Building a personal brand to support my product&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Vibe Coding Reality
&lt;/h2&gt;

&lt;p&gt;"Vibe coding" your way to a successful micro SaaS looks glamorous on Twitter, but the reality is both more challenging and more rewarding than it appears.&lt;/p&gt;

&lt;p&gt;The biggest takeaway? Technical skills are just one piece of the indie hacking puzzle. Being willing to learn, adapt, and push beyond your comfort zone is what ultimately determines success.&lt;/p&gt;

&lt;p&gt;If you're a developer contemplating your own micro SaaS journey, know that the code is just the beginning – but don't let that stop you. The skills you'll develop along the way are invaluable, regardless of the outcome.&lt;/p&gt;

&lt;p&gt;Feel free to check out &lt;a href="https://stickersai.app" rel="noopener noreferrer"&gt;StickersAI&lt;/a&gt; and reach out if you have questions about my indie hacking journey!&lt;/p&gt;

&lt;p&gt;Happy vibe coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Using $ to select HTML elements without using jquery</title>
      <dc:creator>Abde Lazize</dc:creator>
      <pubDate>Mon, 12 Jul 2021 20:38:47 +0000</pubDate>
      <link>https://dev.to/gugocharade/using-to-select-html-elements-without-using-jquery-4leb</link>
      <guid>https://dev.to/gugocharade/using-to-select-html-elements-without-using-jquery-4leb</guid>
      <description>&lt;p&gt;you want to use the dollar sign &lt;code&gt;$&lt;/code&gt; to select HTML elements but you don't want to use Jquery ?&lt;br&gt;
All you need to do is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;$$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let say we have a div with the class &lt;code&gt;container&lt;/code&gt;, you can select it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets say we have multiple inputs with the class &lt;code&gt;input&lt;/code&gt; and we want to select all of them, you can do it like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inputs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you found this post useful give it a like.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>javascript: type conversion and type coercion</title>
      <dc:creator>Abde Lazize</dc:creator>
      <pubDate>Mon, 12 Jul 2021 17:59:36 +0000</pubDate>
      <link>https://dev.to/gugocharade/javascript-type-conversion-and-type-coercion-4oia</link>
      <guid>https://dev.to/gugocharade/javascript-type-conversion-and-type-coercion-4oia</guid>
      <description>&lt;p&gt;Some of the helpful and most used features in JavaScript are type conversion and type coercion, although, they can help you write less and more readable code, they can be the source of bugs especially type coercion, therefore knowing and understanding them will save you from some painful bugs. So what are type conversion and type coercion?&lt;/p&gt;

&lt;p&gt;They both mean converting values from one type to another, for example from string to number, from number to Boolean, etc. but there is a huge difference between them.&lt;/p&gt;

&lt;h2&gt;
  
  
  1- Type conversion:
&lt;/h2&gt;

&lt;p&gt;As we said, it’s changing the type of values, but manually, as an example, let’s say we have the value of an input which is a year of birth and we want to calculate the current age, as you know the type of input value is a String and to do the calculation we need to convert it to a number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt;  &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt;  &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;getFullYear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yearOfBirth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt;  &lt;span class="nx"&gt;currentAge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;yearOfBirth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We stored the input value in the input variable, we get the current year using the getFullYear() method and assigned it to the current year variable, and this is the important part,&lt;br&gt;
we converted the input value which is a string to a number using the Number() function, and finally, we stored the result of the calculation in the current variable.&lt;/p&gt;

&lt;p&gt;In JavaScript, you will always need to perform such conversions, the widely used functions are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;String(): to convert a value to the type of String.&lt;/li&gt;
&lt;li&gt;Number():  to convert a value to the type of Number, but if the value is not a valid number the output will be NaN which means Not a Number (by the way, type of NaN is Number).&lt;/li&gt;
&lt;li&gt;Boolean(): to convert a value to the type of Boolean, true or false.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those functions are very important and useful.&lt;/p&gt;
&lt;h2&gt;
  
  
  2- Type coercion:
&lt;/h2&gt;

&lt;p&gt;This conversion is done automatically by JavaScript, it may look hard to grasp at first but understanding it is crucial for mastering JavaScript.&lt;/p&gt;

&lt;p&gt;Let’s go back to the first example:&lt;br&gt;
Before doing the calculation you need to check if the user submitted his year of birth and you may do it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt;  &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;currentAge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;yearOfBirth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you may know any string but an empty string is true even a string with whitespace that's why we use the trim() method to remove whitespace from both sides of a  string, so If the input value doesn’t equal an empty string then do the calculation, now let’s do it with the coercion in mind :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt;  &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()){&lt;/span&gt;
    &lt;span class="nx"&gt;currentAge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;yearOfBirth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do you see the difference? What’s happening is that JavaScript will automatically convert the input value from a string to a Boolean and if the value is true then do the calculation.&lt;/p&gt;

&lt;p&gt;This behavior exists everywhere in JavaScript, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;  &lt;span class="c1"&gt;// ‘11’&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt; &lt;span class="c1"&gt;// 0&lt;/span&gt;
&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;// 0&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;// 10&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This behavior is weird but it’s beneficial and learning it has a lot of advantages.&lt;br&gt;
I hope you have learned something from this article, if you found it useful don't forget to give it a like.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Storing data in electron</title>
      <dc:creator>Abde Lazize</dc:creator>
      <pubDate>Sun, 11 Jul 2021 20:44:43 +0000</pubDate>
      <link>https://dev.to/gugocharade/storing-data-in-electron-1gd4</link>
      <guid>https://dev.to/gugocharade/storing-data-in-electron-1gd4</guid>
      <description>&lt;p&gt;I created a lot of applications using electron, and the problems I faced were always with persisting data and user preferences.&lt;br&gt;
I had to spend a lot of time and effort trying to save data to a JSON file and trying to update it every time the data changes in the app, so I said to my self why not creating a package that can help me do so.&lt;br&gt;
I started writing the package and adding to it all the features I needed, so after some coding, testing, and debugging I come up with this package called &lt;a href="https://www.npmjs.com/package/electron-data-holder"&gt;electron-data-holder&lt;/a&gt;. BTW it was very difficult to find this name because every name I try is already taken. Nowadays, finding a name for your package is harder than making the package itself.&lt;/p&gt;

&lt;p&gt;This package has a lot of features such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating multiple files each one with its name, for example, a file for storing data and another for storing user preferences.&lt;/li&gt;
&lt;li&gt;Encrypting the data&lt;/li&gt;
&lt;li&gt;Specify the folder where you want to put the JSON files&lt;/li&gt;
&lt;li&gt;The data is watched and the JSON files will be updated after every change&lt;/li&gt;
&lt;li&gt;There is no API to manipulate the data, work with your data as you would do in vanilla Javascript.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Step 1 :
&lt;/h3&gt;

&lt;p&gt;In the main process call &lt;code&gt;initDB()&lt;/code&gt;, this function accepts a configuration object with 2 properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;key : &lt;code&gt;string&lt;/code&gt; &lt;code&gt;(not required)&lt;/code&gt; : the encryption key must be 32 characters long&lt;/li&gt;
&lt;li&gt;customPath : &lt;code&gt;string&lt;/code&gt; &lt;code&gt;(not required)&lt;/code&gt; : The path to the folder where you want to store the JSON files.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;initDB&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;electron-data-holder&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// the encryption key must be 32 characters long.&lt;/span&gt;

&lt;span class="nx"&gt;initDB&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the-encryption-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;customPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the-path-to-the-folder&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The 2 parameters are not required, if you didn't pass an encryption key the data won't be encrypted and if you didn't pass a folder path, the folder will be &lt;code&gt;app.getPath('userData')&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2 :
&lt;/h3&gt;

&lt;p&gt;In the rendrer call &lt;code&gt;storeDB()&lt;/code&gt;, this function accepts 2 parameters :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data object : &lt;code&gt;object&lt;/code&gt; &lt;code&gt;(required)&lt;/code&gt; : The data must be an object.&lt;/li&gt;
&lt;li&gt;Configuration object : &lt;code&gt;(not required)&lt;/code&gt; : accepts 2 properties :

&lt;ul&gt;
&lt;li&gt;fileName : &lt;code&gt;string&lt;/code&gt;: The name is a string and without the &lt;code&gt;.json&lt;/code&gt; part the default is &lt;code&gt;data.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;encryption : &lt;code&gt;boolean&lt;/code&gt; : whether you want the data to be encrypted or not, the default is &lt;code&gt;false&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;storeDB&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;electron-data-holder&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// This function will returns a proxy with your data in it in order to watch the changes and update the JSON file.&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;storeDB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Elon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mask&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;hobbies&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;learning&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;codding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dataFile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;encryption&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// you can create multiple files by giving each one a different name&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;storeDB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;darkMode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;fontSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;fontFamily&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Courier&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Courier&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Everson Mono&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;When the app is launched, it will search for the JSON files and get the data from them if they exist and return it, if not it will use the object you passed as the first parameter.&lt;/p&gt;

&lt;p&gt;After writing these lines of code, you are now ready to work on your app without worrying about the data.&lt;/p&gt;
&lt;h2&gt;
  
  
  Manipulating data
&lt;/h2&gt;

&lt;p&gt;Let's use this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;storeDB&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;electron-data-holder&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;storeDB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Elon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mask&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;hobbies&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;learning&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;coding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dataFile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;encryption&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Reading data
&lt;/h3&gt;

&lt;p&gt;Let's log to the console the first element in the hobbies array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hobbies&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// 'learning'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Modifying data
&lt;/h3&gt;

&lt;p&gt;Let's add "gaming" to the hobbies array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hobbies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gaming&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hobbies&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Proxy {0: "learning", 1: "coding", 2: "gaming"}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's add an "age" property to the user object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;47&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Proxy {firstName: "Elon", lastName: "Mask", age: 47}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;storeDB()&lt;/code&gt; function returns a proxy with your data in it in order to watch the changes and update the JSON file.&lt;br&gt;
Every time you modify your data the JSON file will be updated accordingly.&lt;/p&gt;

&lt;p&gt;As you can see there is no extra stuff for reading and modifying your data and also you don't need to worry about saving it in every change, this package will handle everything for you so you can focus on building your app. HAPPY CODING&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>electronjs</category>
      <category>localstorage</category>
      <category>npm</category>
    </item>
    <item>
      <title>javascript: add an event listener to an inexistent element.</title>
      <dc:creator>Abde Lazize</dc:creator>
      <pubDate>Sat, 21 Nov 2020 18:50:04 +0000</pubDate>
      <link>https://dev.to/gugocharade/javascript-add-an-event-listener-to-an-inexistent-element-59e4</link>
      <guid>https://dev.to/gugocharade/javascript-add-an-event-listener-to-an-inexistent-element-59e4</guid>
      <description>&lt;p&gt;When writing the code for your website or app, manipulating the DOM ( document object model ) is a critical skill you must have, so in this article, we will see how to add an event listener to an inexisted element and also some important tips and tricks to avoid unexpected and weird bugs.&lt;br&gt;
I will be using codepen to better demonstrate the example.&lt;br&gt;
&lt;a href="https://codepen.io/gugocharade/pen/NWroLBv?editors=1111&amp;amp;__cf_chl_jschl_tk__=f12c338e28c51b957f4f94c943d4ffc12f1687a9-1605977634-0-ARbChQoBqRQWglJ1XIseQWAZJZ4G66pwTjId7B7rPXGlt8nSroN16w1JvUwzz1liQo6zHdJEM6fDc5YMuAu9CW_SkmP_sUpctEBpitE05YjyTHhX1S5KXsYArr4fLfpjg5_BoS8qgFDiq62ZTdxqKLJTWQSxK4ipze4TMP7klWzeIjR2i71i3w5aLW7vB5dxK7_cirnK8KxF2F9hmOlR5f_hnZX8evRogJerXq6WH3kvzCIFe7V1-a6Hrr2fZ1QP91LK6eUITX-m8vFoTtb7KwPPLspGdh-bjBrXAIDJD2NDeRfbXbvmRZgqzdKxyIF3khBKrdklqUGCDRX93QEitZ74INMidDYrBvHvVZF8AH72Wji6GNgep_rxdxusJg_FWiS9ACfSDNjhp53bt-s2EEu01AVw-sVvxJ9LDmvcN_Bj"&gt;&lt;strong&gt;the first codepen example&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  1-Adding a click event to the future element:
&lt;/h2&gt;

&lt;p&gt;The HTML I’m using in the first example is just a simple button that says &lt;strong&gt;Go to login page&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;DOM manipulation&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"login"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Go to Login page&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Javascript, I'm adding an event to the button listening for a click, so when the button is clicked, the event function will clear the DOM and insert a login form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;btn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.login&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;btn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;insertAdjacentHTML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;afterbegin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`
  &amp;lt;form action="#" class="form"&amp;gt;
  &amp;lt;input type="email" class="input" placeholder="Email"&amp;gt;
  &amp;lt;input type="password" class="input" placeholder="Password"&amp;gt;

  &amp;lt;button type="submit" class="submit-btn"&amp;gt;Login&amp;lt;/button&amp;gt;
  &amp;lt;/form&amp;gt;
  `&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The future element I'm willing to attach the click event to is the button with class &lt;strong&gt;submit-btn&lt;/strong&gt;, to do so we need to determine the closest and always existing parent (in this example is the body) and attach the click event to it, then we will test if the targeted element has the class &lt;strong&gt;submit-btn&lt;/strong&gt;, if so, I'm going to prevent the form from submitting and just write to the console &lt;strong&gt;you are logged in :)&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.submit-btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)){&lt;/span&gt;
    &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;you are logged in :)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2-Adding a different event to the future element:
&lt;/h2&gt;

&lt;p&gt;What if the event we want to attach is not a click let say it’s a &lt;em&gt;change&lt;/em&gt; event, how we are going to implement it?&lt;br&gt;
&lt;a href="https://codepen.io/gugocharade/pen/vYKqjLp?editors=1111"&gt;&lt;strong&gt;the second codepen example&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The HTML I'm using in this example is a button that says &lt;strong&gt;Choose a car&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;DOM manipulation&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Choose a car&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the javascript I will use in this example is the same but instead of inserting a form, I will insert a select element with cars names as options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;btn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;insertAdjacentHTML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;afterbegin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`
  &amp;lt;label for="cars"&amp;gt;Choose a car:&amp;lt;/label&amp;gt;

&amp;lt;select name="cars" id="cars"&amp;gt;
  &amp;lt;option value="volvo"&amp;gt;Volvo&amp;lt;/option&amp;gt;
  &amp;lt;option value="saab"&amp;gt;Saab&amp;lt;/option&amp;gt;
  &amp;lt;option value="mercedes"&amp;gt;Mercedes&amp;lt;/option&amp;gt;
  &amp;lt;option value="audi"&amp;gt;Audi&amp;lt;/option&amp;gt;
&amp;lt;/select&amp;gt;
  `&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The future element we want to attach the change event to it is the select element, so we will attach a click event to the body (the closest and always existing parent), testing if the targeted element has the ID &lt;strong&gt;cars&lt;/strong&gt; if so, we will add a change event to the select element, in the callback function for the change event I will store the select value in a car variable and write it to the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#cars&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)){&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cars&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;change&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cars&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works, BUT WAIT A MINUTE.&lt;/p&gt;

&lt;p&gt;At first, it looks like it's working, then when you do it again the event fires multiple times, why is that happening?&lt;/p&gt;

&lt;p&gt;The first time I got this error I was about to get crazy, I searched everywhere, I tried all the solutions I found but nothing worked for me, then I started experimenting with my code, and BOOOM I found the solution.&lt;/p&gt;

&lt;p&gt;the problem why this is happening is because each time we click the select element a change event gets attached to it because the callback function we are using is anonymous, so the solution is declaring the function with a name and then use it as a callback.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;eventHandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cars&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#cars&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)){&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cars&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;change&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;eventHandler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I suggest experimenting with it in codepen example so you can get a better understanding of what happening. I won't fix it in the example, I want to give you the chance to fix it your self to understand it and memorize it.&lt;br&gt;
thank you for reading this article, I hope you liked it and learned something from it. And please excuse my English.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>dom</category>
      <category>eventlistener</category>
      <category>html</category>
    </item>
    <item>
      <title>web development: the start</title>
      <dc:creator>Abde Lazize</dc:creator>
      <pubDate>Fri, 13 Nov 2020 17:14:18 +0000</pubDate>
      <link>https://dev.to/gugocharade/web-development-the-start-5gpm</link>
      <guid>https://dev.to/gugocharade/web-development-the-start-5gpm</guid>
      <description>&lt;p&gt;When I first decided to learn web development it took me a long time to figure out the path I will take along this journey, so I watched a lifetime of youtube videos, and I read a ton of articles in which I got to know the different languages and stacks, then I started drawing my roadmap to start the actual learning, so I thought why not share my experience it may help someone to start without losing much time.&lt;/p&gt;

&lt;h3&gt;
  
  
  concepts to grasp
&lt;/h3&gt;

&lt;p&gt;Web development consists of two parts front-end and back-end.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. the front-end&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The front-end is all about the client-side in which you will use  HTML CSS and JAVASCRIPT, those are the main tools you will need to create the client-side, but to call yourself a front-end developer you must learn one of the client-side frameworks such as Angular, React and Vue. You may ask, which is the best framework? There is nothing such a thing, it all depends on your preferences, so to know what suits you better try to make a simple app with all of them so you will end up with the one you prefer. Well, is that all? Actually NO, front-end needs some skills you have to learn and develop  but they require a lot of practice, this is where your creativity will shine and this is what differentiates a front-end developer from another:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Web design:&lt;/strong&gt; mainly focuses on the appearance of a website, the colors, fonts, icons, etc used.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UI design:&lt;/strong&gt; user interface design focuses on making the website look simple and easy to understand by the end-user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UX design:&lt;/strong&gt; user experience design is studying the way users use the website and making changes accordingly by putting the most used parts of the website simple to access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. the back-end&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Also, known as server-side programming,  is all about creating the logic that powers the website or the app you are working on, for the tools you will need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;a programming language:&lt;/strong&gt; there are a variety of programming languages that you can use for example (java, go, c#, python), etc, it’s not like the front-end where you are limited to javascript (you can also use javascript in the back-end with nodejs).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;an operating system:&lt;/strong&gt; you can choose one of the Linux distributions like Ubunto, CentOS, etc, or you can go with Windows or Mac os, pick the one you are comfortable with.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;a web server:&lt;/strong&gt; the web server is just a program that serves the website or application content to the client, the most popular web servers are Apache and Nginx.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;database:&lt;/strong&gt; the database is where your data will be stored you can either go with SQL databases like Mysql, Postgresql, SQLite, etc, or NoSQL databases like MongoDB, MariaDB, CouchDB, etc, try to learn the differences between them and how to choose the best database for your project.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  A roadmap for you
&lt;/h3&gt;

&lt;p&gt;With this massive amount of new technologies, finding your way is very overwhelming. So here is a roadmap you can use to have a smooth and crystal clear learning path, follow this list one by one in the order putted in, the learning resources are limitless, youtube, freecodecamp, etc.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;how the web works&lt;/li&gt;
&lt;li&gt;security in the web&lt;/li&gt;
&lt;li&gt;HTTP and HTTPS&lt;/li&gt;
&lt;li&gt;cookies&lt;/li&gt;
&lt;li&gt;a little bit about networking&lt;/li&gt;
&lt;li&gt;APIs&lt;/li&gt;
&lt;li&gt;HTML and CSS the basics&lt;/li&gt;
&lt;li&gt;javascript the basics&lt;/li&gt;
&lt;li&gt;browser development tools&lt;/li&gt;
&lt;li&gt;the difference between server-side and client-side rendering&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Choose your way
&lt;/h4&gt;

&lt;p&gt;Now you need to choose your way in this Domaine, do you want to be a front-end developer, back-end developer, or a full-stack developer (which means working with the front-end and the back-end).&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;For the front-end :&lt;/strong&gt;
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Advanced Html&lt;/li&gt;
&lt;li&gt;Advanced CSS and Sass&lt;/li&gt;
&lt;li&gt;Advanced javascript&lt;/li&gt;
&lt;li&gt;Nodejs&lt;/li&gt;
&lt;li&gt;Npm&lt;/li&gt;
&lt;li&gt;Webpack&lt;/li&gt;
&lt;li&gt;A front-end framework&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;For the back-end :&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A programming language&lt;/li&gt;
&lt;li&gt;Database&lt;/li&gt;
&lt;li&gt;How to write code with the performance in mind&lt;/li&gt;
&lt;li&gt;How to secure your app&lt;/li&gt;
&lt;li&gt;Authentication types and how to implement them&lt;/li&gt;
&lt;li&gt;How to configure a web server&lt;/li&gt;
&lt;li&gt;The different ways of scaling an application&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Is this all?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Learning all of this won’t make you a pro, now the next step is to make projects and learn from your mistakes, and also you need some skills like :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to search on the web&lt;/li&gt;
&lt;li&gt;How to read the documentation&lt;/li&gt;
&lt;li&gt;How to read others code&lt;/li&gt;
&lt;li&gt;How to debug&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To sum up, continue in your way of learning, never give up and you must know that the hardest part is to keep up with the new technologies and updates happening in this field so you need to be ready. Good luck.&lt;br&gt;
I hope you enjoyed reading this article and learned something from it. thanks for reading.&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
