<?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: Coderslang: Become a Software Engineer</title>
    <description>The latest articles on DEV Community by Coderslang: Become a Software Engineer (@coderslang).</description>
    <link>https://dev.to/coderslang</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%2F521890%2F85a37e43-5caa-44e7-8dce-f999c68ed69a.png</url>
      <title>DEV Community: Coderslang: Become a Software Engineer</title>
      <link>https://dev.to/coderslang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/coderslang"/>
    <language>en</language>
    <item>
      <title>How to get current date in JavaScript</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Tue, 15 Nov 2022 13:48:00 +0000</pubDate>
      <link>https://dev.to/coderslang/how-to-get-current-date-in-javascript-57je</link>
      <guid>https://dev.to/coderslang/how-to-get-current-date-in-javascript-57je</guid>
      <description>&lt;p&gt;There are 2 ways you can get current date in JavaScript. You can just create a new &lt;code&gt;Date&lt;/code&gt; object without&lt;br&gt;
any arguments, or you can use the function &lt;code&gt;Date.now&lt;/code&gt;.&lt;/p&gt;



&lt;p&gt;So both &lt;code&gt;new Date()&lt;/code&gt; and &lt;code&gt;Date.now()&lt;/code&gt; can be used to get current date in JS.&lt;/p&gt;

&lt;p&gt;Let's log the results 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;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="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;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="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the first case, we'll see a date + time in UTC timezone, and with &lt;code&gt;Date.now&lt;/code&gt; we'll get the number of milliseconds&lt;br&gt;
passed after Jan 1, 1970.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2022-01-13T15:19:32.557Z
1642087172563
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both results represent current date in JavaScript and can be easily compared.&lt;/p&gt;

&lt;p&gt;A date object can be converted to milliseconds since Jan 1, 1970 by using a &lt;code&gt;getTime&lt;/code&gt; method.&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="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;getTime&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 1642087361849&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you can convert milliseconds returned by &lt;code&gt;Date.now()&lt;/code&gt; to a Date object, although it's pretty redundant.&lt;br&gt;
If you just need current date, it's better to call &lt;code&gt;new Date()&lt;/code&gt; without arguments.&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="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="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt; &lt;span class="c1"&gt;// 2022-01-13T15:24:55.969Z&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to update all npm package.json dependencies to the latest version</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Mon, 14 Nov 2022 13:30:00 +0000</pubDate>
      <link>https://dev.to/coderslang/how-to-update-all-npm-packagejson-dependencies-to-the-latest-version-4okn</link>
      <guid>https://dev.to/coderslang/how-to-update-all-npm-packagejson-dependencies-to-the-latest-version-4okn</guid>
      <description>&lt;p&gt;It's essential to keep all the node modules of your project up to date as the security patches go out.&lt;/p&gt;

&lt;p&gt;In this short tutorial I'll teach you how to update all the &lt;code&gt;node_modules&lt;/code&gt; to the latest version with a single command.&lt;/p&gt;

&lt;p&gt;By default, once you type &lt;code&gt;npm install &amp;lt;package_name&amp;gt;&lt;/code&gt;, node package manager installs the latest version of&lt;br&gt;
the desired package. This version is then added automatically to the file &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The issue is that over time new versions of the packages are being released, and you need to somehow update them.&lt;/p&gt;

&lt;p&gt;To check which packages are outdated, you can run the command &lt;code&gt;npm outdated&lt;/code&gt;, however &lt;br&gt;
Node Package Manager (npm), doesn't update dependencies from &lt;code&gt;package.json&lt;/code&gt; by default.&lt;/p&gt;

&lt;p&gt;So, if you're looking to update all the npm modules with a single command, you can use the module &lt;code&gt;npm-check-updates&lt;/code&gt;.&lt;br&gt;
It's best to install this module globally with the &lt;code&gt;-g&lt;/code&gt; flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; npm-check-updates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After successful installation, you'll be able to use the command &lt;code&gt;ncu&lt;/code&gt; from the command line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ncu &lt;span class="nt"&gt;-u&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure that you navigate to your project directory before using the &lt;code&gt;ncu -u&lt;/code&gt; command. Once you execute it,&lt;br&gt;
&lt;code&gt;npm-check-updates&lt;/code&gt; will update all the dependencies from &lt;code&gt;package.json&lt;/code&gt; to the fresh versions.&lt;/p&gt;

&lt;p&gt;The last step is to run the command &lt;code&gt;npm install&lt;/code&gt; to download and install updated packages based on the information&lt;br&gt;
in &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>The difference between dependencies and devDependencies in package.json</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Sun, 13 Nov 2022 13:45:17 +0000</pubDate>
      <link>https://dev.to/coderslang/the-difference-between-dependencies-and-devdependencies-in-packagejson-1p49</link>
      <guid>https://dev.to/coderslang/the-difference-between-dependencies-and-devdependencies-in-packagejson-1p49</guid>
      <description>&lt;p&gt;The file &lt;code&gt;package.json&lt;/code&gt; is an integral part of every Node.js project. It stores all the dependencies that your&lt;br&gt;
project needs.&lt;/p&gt;

&lt;p&gt;All the dependencies (most often open-source npm modules) are split into two categories: production dependencies&lt;br&gt;
and development dependencies.&lt;/p&gt;

&lt;p&gt;The difference between the two is that development dependencies won't be installed in the production environment&lt;br&gt;
as they aren't needed there. It could be something that checks the quality of your code like &lt;code&gt;ESLint&lt;/code&gt;, debug tools&lt;br&gt;
like &lt;code&gt;Nodemon&lt;/code&gt; ot testing helpers like &lt;code&gt;Chai&lt;/code&gt;, &lt;code&gt;Mocha&lt;/code&gt;, &lt;code&gt;Enzyme&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can include production dependencies by running the &lt;code&gt;npm install --save&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;For example, here's how you'd install the module &lt;code&gt;express&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the installation is complete it will appear in the list of &lt;code&gt;dependencies&lt;/code&gt; in &lt;code&gt;package.json&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"my_node_project"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"express"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^4.18.11"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To install the development dependency, you'll need to use the flag &lt;code&gt;--save-dev&lt;/code&gt; instead of the &lt;code&gt;--save&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; mocha
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way the module will appear in the section &lt;code&gt;devDependencies&lt;/code&gt; in &lt;code&gt;package.json&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"my_node_project"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"express"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^4.18.11"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"devDependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"mocha"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^10.0.0"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once it's clear how to add the different types of dependencies (dev and prod) to your Node.js project, &lt;br&gt;
you should learn how to install them separately or all at once.&lt;/p&gt;

&lt;p&gt;To install only dev dependencies from an existing &lt;code&gt;package.json&lt;/code&gt; you can use either the full command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--only&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or a shorter version&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To install only production dependencies, you can use the same flag &lt;code&gt;--only&lt;/code&gt;, but now with the argument &lt;code&gt;prod&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--only&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;prod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks for reading! I hope this tutorial helped you understand the difference between development and production&lt;br&gt;
dependencies in &lt;code&gt;package.json&lt;/code&gt; and you learned how to use either of them in you Node.js projects.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>node</category>
    </item>
    <item>
      <title>Programming Methodologies: Agile vs Waterfall</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Wed, 09 Nov 2022 17:10:31 +0000</pubDate>
      <link>https://dev.to/coderslang/programming-methodologies-agile-vs-waterfall-299b</link>
      <guid>https://dev.to/coderslang/programming-methodologies-agile-vs-waterfall-299b</guid>
      <description>&lt;p&gt;Programming methodology is a system of rules and guidelines used by programmers to create software. It includes a set of best practices, tools and techniques that help programmers write high-quality code.&lt;/p&gt;

&lt;p&gt;There are many different programming methodologies, each with its own strengths and weaknesses. The most popular ones are &lt;strong&gt;waterfall&lt;/strong&gt; and &lt;strong&gt;agile&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Waterfall
&lt;/h2&gt;

&lt;p&gt;Waterfall programming methodology is a sequential design process, often used in software development, that is characterized by distinct phases of activity. In waterfall methodology, progress flows in a linear, sequential fashion from one phase to the next.&lt;/p&gt;

&lt;h3&gt;
  
  
  Waterfall advantages
&lt;/h3&gt;

&lt;p&gt;The main advantage of waterfall methodology is its predictability. Because each phase has specific deliverables and a review process, it is relatively easy to manage risk and identify potential problems early on. This makes waterfall well-suited for projects where requirements are very well understood.&lt;/p&gt;

&lt;h3&gt;
  
  
  Waterfall disadvantages
&lt;/h3&gt;

&lt;p&gt;Waterfall also has some disadvantages. One is that it can be inflexible; once a project moves into a later stage, it can be difficult to make changes without potentially jeopardizing the entire project. Additionally, because waterfall relies on a linear progression, it does not lend itself well to projects with rapidly changing or unpredictable requirements.&lt;/p&gt;

&lt;p&gt;Despite its drawbacks, waterfall remains one of the most popular software development methodologies due to its simplicity and predictability. When applied correctly to an appropriate project, it can help ensure smooth progress and successful delivery.&lt;/p&gt;

&lt;h2&gt;
  
  
  Agile
&lt;/h2&gt;

&lt;p&gt;Agile is a more modern approach that is based on iteration and constant feedback from users. It is more flexible than waterfall and can handle changes more easily. However, it can be more difficult to plan and estimate timelines for projects using agile.&lt;/p&gt;

&lt;p&gt;Agile programming is a methodology for developing software in which requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development, early delivery, and continuous improvement, and it encourages rapid and flexible response to change.&lt;/p&gt;

&lt;p&gt;The agile approach began in the software development community, but has since been adopted by organizations of all types and sizes. Agile programming is based on the values and principles outlined in the Agile Manifesto.&lt;/p&gt;

&lt;p&gt;There are many different agile methods or frameworks, each with its own set of practices and terminology. The most popular agile methods are Scrum, Kanban, Lean, and Extreme Programming (XP).&lt;/p&gt;

&lt;h3&gt;
  
  
  Agile advantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Increased flexibility: Agile programming helps organizations respond quickly to changes in market conditions or customer needs. This is because the agile approach encourages constant feedback and allows for course corrections throughout the development process. As a result, organizations can avoid the costly mistakes that can occur when plans are set in stone too far in advance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improved quality: The focus on collaboration and constant feedback helps to ensure that errors are caught early and that features are developed with the user in mind. This leads to higher quality software that is more likely to meet the needs of its users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Greater transparency: The use of short development cycles (known as sprints) makes it easy to track progress and identify issues early on. This transparency helps to build trust between developers and stakeholders.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enhanced team morale: The collaborative nature of agile programming fosters a sense of ownership and responsibility among team members. This can lead to higher levels of engagement and satisfaction within the team.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Agile Disadvantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A greater need for discipline: Because agile programming relies heavily on self-organizing teams, it requires a high degree of discipline from both developers and stakeholders. Without this discipline, it can be difficult to stay on track and make progress towards objectives.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Risk of scope creep: The iterative nature of agile programming means that there is always the potential to add new features or make changes to existing ones. This can lead to scope creep – the uncontrolled expansion of a project’s scope – which can ultimately cause delays and cost overruns.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A higher level of complexity: The use of multiple agile methods or frameworks can lead to a higher level of complexity, which can make it difficult for new team members to get up to speed. In addition, the constant change that is characteristic of agile programming can also add to the complexity.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How Long it Takes to Learn CSS</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Mon, 27 Sep 2021 11:49:35 +0000</pubDate>
      <link>https://dev.to/coderslang/how-long-it-takes-to-learn-css-44im</link>
      <guid>https://dev.to/coderslang/how-long-it-takes-to-learn-css-44im</guid>
      <description>&lt;p&gt;Like HTML, CSS is also simple to learn because there are few concepts to remember it. These concepts include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CSS syntax&lt;/li&gt;
&lt;li&gt;Common CSS properties&lt;/li&gt;
&lt;li&gt;The CSS Box Model&lt;/li&gt;
&lt;li&gt;How to find more information&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  CSS syntax
&lt;/h2&gt;

&lt;p&gt;The first concept to remember is to know the syntax of CSS. In essence, the CSS syntax comes in three parts. They are the selectors, property, and value.&lt;/p&gt;

&lt;p&gt;Here's a basic example of the CSS syntax. It tells CSS to change the color of the &lt;code&gt;h1&lt;/code&gt; element into red color:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&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;Let me explain what's happening in this code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;h1&lt;/code&gt; is the CSS selector, and it points to the HTML element that you want to change styles. In this case, we select the &lt;code&gt;h1&lt;/code&gt; element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;color&lt;/code&gt; is the CSS property, and it tells what type of styling you want to apply. In this case, change the color of the &lt;code&gt;h1&lt;/code&gt; element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;red&lt;/code&gt; is the CSS property value, and it tells how the style should change. In this case, change the &lt;code&gt;h1&lt;/code&gt; element color to red.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As long as you remember the syntax, then you pretty much know half of the CSS rules. The other half comes from experiences (making mistakes and learning from them) and regular practice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common CSS properties
&lt;/h2&gt;

&lt;p&gt;The next concept to know is the CSS properties. While CSS has more than a hundred properties, there are few of them you will use frequently. These common CSS properties include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Colors&lt;/li&gt;
&lt;li&gt;Width and Height&lt;/li&gt;
&lt;li&gt;Background&lt;/li&gt;
&lt;li&gt;Background color&lt;/li&gt;
&lt;li&gt;Font size&lt;/li&gt;
&lt;li&gt;Margin and Padding&lt;/li&gt;
&lt;li&gt;Border&lt;/li&gt;
&lt;li&gt;Display&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By knowing these common CSS properties, you will have the foundations to build simple websites. As for the rest of the CSS properties, you will learn them when you need them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The CSS Box Model
&lt;/h2&gt;

&lt;p&gt;The third concept to remember is knowing what the CSS box model is.&lt;/p&gt;

&lt;p&gt;Every HTML element wraps around a box called the box model. This box model consists of multiple properties which are margins, paddings, borders, and content. The purpose of the box model is to help you design and build the layout of a web page. It is also a handy tool for identifying issues in CSS stylings.&lt;/p&gt;

&lt;p&gt;Learning CSS Box Model is challenging at first. But with enough time and practice, it will make sense to you. Plus, once you've learned it, you will have a deep understanding of CSS and be able to build complex web designs.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to find more information
&lt;/h2&gt;

&lt;p&gt;The last concept to remember is knowing how to find more information about CSS.&lt;/p&gt;

&lt;p&gt;It is crucial to know how to search because a lot of times, you will spend your time googling how to add stylings in CSS and fix any issues you encounter when building a layout of a web page.&lt;/p&gt;

&lt;p&gt;The first place to start is MDN Web Docs. It is an official documentation website where you can learn anything related to CSS. Another good website to look for CSS information is CSS-Tricks and &lt;a href="https://learn.coderslang.com/tags/css/"&gt;Coderslang&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;To sum it up, it will probably take you few weeks to learn the basics of CSS. As long as you keep the CSS concepts in mind, like the box modal, syntax, and practice regularly, you will become good at CSS within one or two months.&lt;/p&gt;

&lt;p&gt;I hope you find this article helpful, and good luck learning CSS!&lt;/p&gt;

&lt;p&gt;Get my &lt;a href="https://learn.coderslang.com/free-ebooks/"&gt;free e-book&lt;/a&gt; to prepare for the technical interview or start to &lt;a href="https://js.coderslang.com/"&gt;Learn Full-Stack JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How Long it Takes to Learn HTML</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Tue, 21 Sep 2021 13:48:42 +0000</pubDate>
      <link>https://dev.to/coderslang/how-long-it-takes-to-learn-html-30h7</link>
      <guid>https://dev.to/coderslang/how-long-it-takes-to-learn-html-30h7</guid>
      <description>&lt;p&gt;It will take 2-3 weeks to learn the basics of HTML and 1-2 months of practice to be good at it. Depending on how many hours a day you spend learning, you will learn HTML sooner or later. I recommend at least one hour a day for complete beginners.&lt;/p&gt;

&lt;p&gt;HTML is quite simple to learn as there are few things to remember about the language, and that is knowing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What HTML does&lt;/li&gt;
&lt;li&gt;What opening and closing tags are&lt;/li&gt;
&lt;li&gt;Common element tags used for building a website, and&lt;/li&gt;
&lt;li&gt;Where to search for more information&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What HTML does
&lt;/h2&gt;

&lt;p&gt;The first important thing to remember is to understand what exactly HTML does. In essence, HTML creates the contents of the web page. HTML can make texts, images, videos, links, navigation, and so on. The article you are reading right now is done in HTML too.&lt;/p&gt;

&lt;p&gt;That's pretty much of it. All HTML does is defines the structures and contents of a website. To make your website look more beautiful and professional, you will have to use another tool called CSS. You will learn more about CSS later, but let's focus on HTML for now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Opening and closing tags
&lt;/h2&gt;

&lt;p&gt;Most HTML elements have two tags, and they are opening tags and closing tags. When you want to create something in HTML, you will start with opening tag &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt; and end it with a closing tag &lt;code&gt;&amp;lt;/&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Examples of opening tags and closing tags:&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="nt"&gt;&amp;lt;h1&amp;gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Some elements can have only one tag and do not require opening and closing tags.&lt;/p&gt;

&lt;p&gt;Examples of elements with no opening and closing tags:&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="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Main element tags
&lt;/h2&gt;

&lt;p&gt;HTML has so many elements, but luckily, you will need a few of them to use every day. Some common elements include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;h1&lt;/strong&gt; - this element will create a heading text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;p&lt;/strong&gt; - this element will create a paragraph.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;button&lt;/strong&gt; - this element will create a button.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;a&lt;/strong&gt; - this element will create a hyperlink.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;input&lt;/strong&gt; - this element will create an input field where a user can enter data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;li&lt;/strong&gt; - this element will create a bullet point for making a list.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;header&lt;/strong&gt; - this element will create a header of a web page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;nav&lt;/strong&gt; - this element will create a navigation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;footer&lt;/strong&gt; - this element will create a footer of the web page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;div&lt;/strong&gt; - this element will divide the web page into sections.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;img&lt;/strong&gt; - this element will create an image for a web page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don't need to memorize them all since you can always look up the reference on the internet. Besides, when you use them regularly, you will eventually remember them on your own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to search for more information
&lt;/h2&gt;

&lt;p&gt;The last important point is that there are still more lot of things you don't know yet. When you want to learn how to build certain things for a website or get more information about HTML, you can search for them with the help of Google.&lt;/p&gt;

&lt;p&gt;The first place to start looking for information is MDN Web Docs. It is an official documentation website that has everything you need to know about HTML and web development in general.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In a nutshell, you will probably have to spend at least one hour a day learning HTML. Plus, you have to remember what HTML does, what opening and closing tags are, common element tags used, and where to search for more information.&lt;/p&gt;

&lt;p&gt;As long as you keep these points in mind, you'll learn HTML in no time.&lt;/p&gt;

&lt;p&gt;Get my &lt;a href="https://learn.coderslang.com/free-ebooks/"&gt;free e-book&lt;/a&gt; to prepare for the technical interview or start to &lt;a href="https://js.coderslang.com/"&gt;Learn Full-Stack JavaScript&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;P.S. I'm glad you made it here :). Make sure to smash the like buttons and read my other "How Long it Takes..." articles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://learn.coderslang.com/0123-how-long-does-it-take-to-learn-css/"&gt;How Long it Takes to Learn CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.coderslang.com/0062-how-long-does-it-take-to-learn-to-code/"&gt;How Long it Takes to Learn to Code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.coderslang.com/0091-how-long-it-takes-to-learn-javascript/"&gt;How Long it Takes to Learn JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>html</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How to Remove Underlines From Links with CSS</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Tue, 21 Sep 2021 13:39:37 +0000</pubDate>
      <link>https://dev.to/coderslang/how-to-remove-underlines-from-links-with-css-42kk</link>
      <guid>https://dev.to/coderslang/how-to-remove-underlines-from-links-with-css-42kk</guid>
      <description>&lt;p&gt;You know how hyperlinks always come with an underline, right? And you want to get rid of it so you can add your style. Well, you can do it by using the &lt;code&gt;text-decoration&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;text-decoration&lt;/code&gt; is a CSS property that will specify how to decorate the text. Since the hyperlink by default has a decoration, all you have to do is remove the text-decoration from the link.&lt;/p&gt;

&lt;h2&gt;
  
  
  An example code
&lt;/h2&gt;

&lt;p&gt;Let us take an example of how to remove underline with the &lt;code&gt;text-decoration&lt;/code&gt; property.&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&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&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;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;http-equiv=&lt;/span&gt;&lt;span class="s"&gt;"X-UA-Compatible"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"IE=edge"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Example&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;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Definitely not a clickbait&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/style&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;As shown from the example code above, the &lt;code&gt;text-decoration: none;&lt;/code&gt; basically tells the CSS not to have any decoration on the hyperlink. That means the hyperlink no longer has an underline.&lt;/p&gt;

&lt;p&gt;And that is pretty much it. Quite simple, right?&lt;/p&gt;

&lt;p&gt;Get my &lt;a href="https://learn.coderslang.com/free-ebooks/"&gt;free e-book&lt;/a&gt; to prepare for the technical interview or start to &lt;a href="https://js.coderslang.com/"&gt;Learn Full-Stack JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>css</category>
      <category>html</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>JavaScript Design Patterns - Decorator</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Tue, 14 Sep 2021 11:34:00 +0000</pubDate>
      <link>https://dev.to/coderslang/javascript-design-patterns-decorator-1d57</link>
      <guid>https://dev.to/coderslang/javascript-design-patterns-decorator-1d57</guid>
      <description>&lt;p&gt;Decorator is one of the &lt;em&gt;Structural Design Patterns&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You're about to start with gift wrapping for a birthday party. A delicate, fragile gift has to be bubble-wrapped. It is followed by placing it safely in a cardboard box. The box itself may be wrapped with shining wrapping paper. Finally, finishing it off with an elegant winding of a satin ribbon around it.&lt;/p&gt;

&lt;p&gt;These layers and more are added to or removed from the gift as randomly as our creative thoughts flow. The gift object, however, remains unperturbed. But, the packaging makes it look a lot better for the handover.&lt;/p&gt;

&lt;p&gt;Similar to the example quoted above, the decorator pattern is merely a conceptualized way of enhancing the properties or functionalities of objects with respect to their design.&lt;/p&gt;

&lt;p&gt;The decorator aids in adding or removing properties or functionalities to objects without having to alter the structure of the object. To emphasize, the original object remains unmodified/constant. The new features are essentially wrapped around the object without coming in contact with it.&lt;/p&gt;

&lt;p&gt;Here is another example of having to build models of Headphones. There are different kinds of them. How about considering  Wireless and Waterproof Headphones for now?&lt;br&gt;
Let's take a look at a probable initial design for this:&lt;/p&gt;

&lt;p&gt;We have a concrete  &lt;code&gt;Headphone&lt;/code&gt; class. &lt;code&gt;WirelessHeadPhone&lt;/code&gt; and &lt;code&gt;WaterproofHeadPhone&lt;/code&gt; are its two subclasses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Headphone&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WirelessHeadPhone&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Headphone&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isWired&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WaterproofHeadPhone&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Headphone&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isWaterproof&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="err"&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;What if now, there comes a new requirement to make the headphones both waterproof and wireless in combination? What would you do? Should my new WaterProof and Wireless Headphone be extending the WirelessHeadPhone class? Inheritance doesn't provide a way to subclass from multiple classes. A subclass can only have one parent class. How do I decide which class to extend it from now? Extending from any class would not make too much of a difference here. I'd give up and go for doing something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WaterProofAndWirelessHeadphone&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Headphone&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isWaterproof&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isWired&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;170&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;This definitely solves the problem. Just when you start thinking you are done with this, now the company wants to introduce Headphones for Kids.&lt;/p&gt;

&lt;p&gt;Now you have another class, the Headphone class needs to be extended to.&lt;/p&gt;

&lt;p&gt;Finally, this is what we arrive at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BabyEarHeadphone&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Headphone&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Small&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="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;80&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;The requirements just don't stop there. You may have to have a number of permutations on each of the existing features and will have new incoming features.&lt;/p&gt;

&lt;p&gt;This shows that adding a subclass for every new requirement makes them too many in number. This results in what we call class explosion.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flearn.coderslang.com%2FClassExplosion.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flearn.coderslang.com%2FClassExplosion.png" alt="class explosion in javascript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is where Decorator comes into play, providing a much more elegant and flexible alternative solution.&lt;/p&gt;

&lt;p&gt;We have now seen that adding new features to a class can be achieved using class extension/inheritance. But for scenarios where the depth of inheritance increases, it gets out of hand, resulting in too many subclasses. Maintenance of design as such would turn into a nightmare. Decorator pattern helps avoid this problem.&lt;/p&gt;

&lt;p&gt;These new features are attached to the objects, using Decorator Pattern, only during runtime, not before that.&lt;/p&gt;

&lt;p&gt;The decorator's abstraction has two flavors to it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The decorator itself acts as an interface to the object it wraps.&lt;/li&gt;
&lt;li&gt;The decorator has the properties of the object it wraps.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To keep everything as simple as possible, consider an example for cupcake making. &lt;code&gt;CupCake&lt;/code&gt; here is a concrete class. Adding sprinkles, chocolate chips, frosting are its decorators. The pricing for a cupcake depends on the decorators added to it. In its simplest form, the decorator pattern looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CupCake&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flavour&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;flavour&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;flavour&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&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;A &lt;code&gt;cupcake&lt;/code&gt; is an object that needs to be decorated.&lt;/p&gt;

&lt;p&gt;Let's look at our first decorator, &lt;code&gt;addSprinkles&lt;/code&gt;. The decorator accepts an instance of &lt;code&gt;Cupcake&lt;/code&gt; as its input. The decorator now wraps the original object to append an additional property to it, keeping the object's structure intact and not modifying it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;//decorator 1&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addSprinkles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cupcake&lt;/span&gt;&lt;span class="p"&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;cost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cupcake&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cost&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;cupcake&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;hasSprinkles&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="nx"&gt;cost&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;We can allow an unlimited number of decorators to wrap around the object, just by sending the instance of it around to each decorator responsible for their individual capability to enhance the object's functionalities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;//decorator 2&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addSkittles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cupcake&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cupcake&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cost&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="err"&gt; &lt;/span&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;cupcake&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;hasSprinkles&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="nx"&gt;cost&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;Finally, this is the Cupcake decorated with sprinkles and/or with skittles!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;vanilla&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CupCake&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vanilla&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;blue&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;sprinkledVanilla&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;addSprinkles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vanilla&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;skittleVanilla&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;addSkittles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vanilla&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//A combination of both sprinkle decorator and skittle decorator.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fullDecoratedVanilla&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;addSkittles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sprinkledVanilla&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vanilla&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cost&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//3&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sprinkledVanilla&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cost&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//4&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;skittleVanilla&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cost&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//5&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fullDecoratedVanilla&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cost&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that Javascript is a dynamic language. The ability to extend its functionality is extremely simple, an inherent feature of the language in itself.&lt;br&gt;
For a statically typed programming language, however, the decorator pattern's flexibility makes much of a difference.  The advantage is with the capability to adapt to changes during the run time, especially when compared to the compile-time changes that inheritance provides.&lt;/p&gt;

&lt;p&gt;Get my &lt;a href="https://learn.coderslang.com/free-ebooks/" rel="noopener noreferrer"&gt;free e-book&lt;/a&gt; to prepare for the technical interview or start to &lt;a href="https://js.coderslang.com" rel="noopener noreferrer"&gt;Learn Full-Stack JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What does CRUD stand for in programming</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Fri, 10 Sep 2021 07:11:37 +0000</pubDate>
      <link>https://dev.to/coderslang/what-does-crud-stand-for-in-programming-4kj1</link>
      <guid>https://dev.to/coderslang/what-does-crud-stand-for-in-programming-4kj1</guid>
      <description>&lt;p&gt;CRUD stands for &lt;strong&gt;Create, Read, Update, and Delete&lt;/strong&gt;. CRUD is the basic operations of the database management system (DBMS), and is used when you want to create, view, edit, or remove the data inside the application's database.&lt;/p&gt;

&lt;p&gt;Any organization and application software that needs to store information like user account information, shop items, payments, etc., will often keep them in a database. And to manage these databases, you will need CRUD operations to perform the functions of creating, updating, and removing the data.&lt;/p&gt;

&lt;p&gt;A programmer can change these data through writing code, or a user through interacting with graphical user interfaces (GUI).&lt;/p&gt;

&lt;h2&gt;
  
  
  How CRUD exactly works
&lt;/h2&gt;

&lt;p&gt;To get an idea of how CRUD works, let's pretend that you are managing an e-commerce website.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Create
&lt;/h3&gt;

&lt;p&gt;When you got a new product from the supplier and want to list it on your website, so your customers can see the product and buy it, you use the Create operation. The Create operation allows you to add new data to the database.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Read
&lt;/h3&gt;

&lt;p&gt;When you are looking for a specific product and use the search bar to find the product, you are using the Read operation. The Read operation allows you to search and retrieve the data that you have created in the database. It won't modify the data or alter it in other ways - you can only read the data, and that's about it.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Update
&lt;/h3&gt;

&lt;p&gt;When you spot a typo in one of the product names and want to edit it before the customer sees your mistake, you use the Update operation. The Update operation allows you to change the existing data that you have created in the database. You also use the update operation when you want to add more information to the product.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Delete
&lt;/h3&gt;

&lt;p&gt;When you want to remove the product from your website because the manufacturer has stopped producing it, and it's no longer available in the market, you use the Delete operation. The Delete operation allows you to remove the data from the database that you don't need anymore.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why CRUD is important
&lt;/h2&gt;

&lt;p&gt;The CRUD concept may be simple enough, but all the world's most popular applications follow the CRUD pattern when you think about it. Google, Windows Office, Facebook, PayPal, Amazon, Uber, and others used CRUD as a model to build the application. Without the CRUD operations, it will be impossible to make these applications.&lt;/p&gt;

&lt;p&gt;CRUD is very important because it helps you think about how to design an application that relies on user's data. If you understand the CRUD concept and can create, view, modify and remove the data from the database, you can virtually create any application you can imagine.&lt;/p&gt;

&lt;p&gt;Get my &lt;a href="https://learn.coderslang.com/free-ebooks/"&gt;free e-book&lt;/a&gt; to prepare for the technical interview or start to &lt;a href="https://js.coderslang.com"&gt;Learn Full-Stack JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>programming</category>
      <category>database</category>
    </item>
    <item>
      <title>What does return do in JavaScript</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Thu, 09 Sep 2021 13:06:21 +0000</pubDate>
      <link>https://dev.to/coderslang/what-does-return-do-in-javascript-1c4g</link>
      <guid>https://dev.to/coderslang/what-does-return-do-in-javascript-1c4g</guid>
      <description>&lt;p&gt;Like other programming languages, JavaScript allows using &lt;code&gt;return&lt;/code&gt; statements in functions. A &lt;code&gt;return&lt;/code&gt; statement does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Halts function execution and returns control to calling module&lt;/li&gt;
&lt;li&gt;Returns one or many values. This is optional.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this tutorial, you'll learn more about syntax and usage of this return statement. &lt;/p&gt;

&lt;h2&gt;
  
  
  The general syntax
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;return&lt;/code&gt; statement has the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The keyword &lt;code&gt;value&lt;/code&gt; refers to a value that will be returned by your function. This is optional. You can use a return statement without specifying any value.&lt;/p&gt;

&lt;p&gt;You can use a single value variable such as string, integer, etc to return a single value. &lt;/p&gt;

&lt;p&gt;You can use an array with a &lt;code&gt;return&lt;/code&gt; statement, if you need return many values. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;return&lt;/code&gt; statement also can return objects of user defined types.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding Samples
&lt;/h2&gt;

&lt;p&gt;Here comes a few simple examples. It helps in learning various ways to use return statements in JavaScript functions.&lt;/p&gt;

&lt;p&gt;You can use the return statement to put an immediate halt in function execution and return a value -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;checkPrimeNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&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;num&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&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;num&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&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;num&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&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="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;checkPrimeNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function &lt;code&gt;checkPrimeNumber()&lt;/code&gt; accepts a number as parameter. It checks if the number is a prime number or not. Once it makes a decision, it halts execution and return a true or false value to calling module. &lt;/p&gt;

&lt;p&gt;The example passes a prime number, 7 as input. Thus the program responds with a &lt;code&gt;true&lt;/code&gt; value. You can try running the source code with different input values. &lt;/p&gt;

&lt;p&gt;Often developers use a return statement with no value, to stop the function execution. The below example uses the function &lt;code&gt;greetUser()&lt;/code&gt; to display a greetings message to the user. The function uses a return statement with no value to halt the function execution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&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;greetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Steve&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 program outputs a message, "Hello Steve!".&lt;/p&gt;

&lt;p&gt;A return statement can return user-defined types also. The below functions return JavaScript objects and an array of objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Example of a return statement returns an object&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;returnObj&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;FirstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;LastName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Course&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;student&lt;/span&gt; &lt;span class="o"&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="nx"&gt;FirstName&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="nx"&gt;LastName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;course&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Course&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;student&lt;/span&gt;&lt;span class="p"&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;returnObj&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&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="s2"&gt;Smith&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="s2"&gt;Chemistry&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Example of a return statement returns an array of objects&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;returnObjectArray&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;student&lt;/span&gt; &lt;span class="o"&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="s2"&gt;John&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="s2"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;course&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Physics&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;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Steve&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="s2"&gt;Owen&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;course&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chemistry&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}];&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;student&lt;/span&gt;&lt;span class="p"&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;returnObjectArray&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Any JavaScript console can run the above source code. You can try experimenting, modifying these programs, or writing something new.&lt;/p&gt;

&lt;p&gt;Get my &lt;a href="https://learn.coderslang.com/free-ebooks/"&gt;free e-book&lt;/a&gt; to prepare for the technical interview or start to &lt;a href="https://js.coderslang.com"&gt;Learn Full-Stack JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JavaScript Interview Question #50: How does Intl.Collator work in JS</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Sun, 27 Jun 2021 07:33:05 +0000</pubDate>
      <link>https://dev.to/coderslang/javascript-interview-question-50-how-does-intl-collator-work-in-js-3ff8</link>
      <guid>https://dev.to/coderslang/javascript-interview-question-50-how-does-intl-collator-work-in-js-3ff8</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flearn.coderslang.com%2Fjs-test-50.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flearn.coderslang.com%2Fjs-test-50.png" alt="javascript interview question #50"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What is &lt;code&gt;Intl.Collator&lt;/code&gt; and how does it work in JS? What’s the difference between two sorts? What will be logged to the console?&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Intl.Collator&lt;/code&gt; object allows you to compare strings with regard to locale and internationalization.&lt;/p&gt;

&lt;p&gt;Normal sort compares strings character by character using ASCII codes. First, there will always appear strings that start with capital letters, and only then, the ones that stat with small letters.&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&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;Z&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;a&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;z&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// ['A', 'Z', 'a', 'z']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Intl.Collator&lt;/code&gt; solves this problem and several others. For example, in German, the letter &lt;code&gt;ä&lt;/code&gt; comes after &lt;code&gt;a&lt;/code&gt;, and in Swedish, it’s at the very end of the alphabet, after &lt;code&gt;z&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can select the desired locale and get a sorted array of strings according to all the rules of that locale.&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;b&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;a&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;z&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;ä&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Collator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;de&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;compare&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;b&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;a&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;z&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;ä&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Collator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'a'&lt;/span&gt;, &lt;span class="s1"&gt;'ä'&lt;/span&gt;, &lt;span class="s1"&gt;'b'&lt;/span&gt;, &lt;span class="s1"&gt;'z'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'a'&lt;/span&gt;, &lt;span class="s1"&gt;'b'&lt;/span&gt;, &lt;span class="s1"&gt;'z'&lt;/span&gt;, &lt;span class="s1"&gt;'ä'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;ANSWER&lt;/strong&gt;: Two sorted arrays will appear on the screen. The first will be collated according to the rules of the &lt;code&gt;en&lt;/code&gt; locale for &lt;code&gt;Intl.Collator&lt;/code&gt;. The second sorting of strings will be case-sensitive. At the beginning, there will be words starting with a capital letter, and words with small letters at the end.&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="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;America&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;apple&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;bloom&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;Boston&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;zebra&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;America&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;Boston&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;apple&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;bloom&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;zebra&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;&lt;a href="https://js.coderslang.com" rel="noopener noreferrer"&gt;Learn Full-Stack JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>JavaScript Interview Question #49: Add a new array element by index</title>
      <dc:creator>Coderslang: Become a Software Engineer</dc:creator>
      <pubDate>Wed, 23 Jun 2021 03:55:04 +0000</pubDate>
      <link>https://dev.to/coderslang/javascript-interview-question-49-add-a-new-array-element-by-index-2n8f</link>
      <guid>https://dev.to/coderslang/javascript-interview-question-49-add-a-new-array-element-by-index-2n8f</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flearn.coderslang.com%2Fjs-test-49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flearn.coderslang.com%2Fjs-test-49.png" alt="coderslang javascript interview question #49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Will the length of the JS array change? What’s the output?&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;All JavaScript arrays have the &lt;code&gt;push&lt;/code&gt; function. It’s used to add new elements to the 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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// [ 1, 2, 3]&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [ 1, 2, 3, 500]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use an array index to read a certain element or modify it:&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;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;arr&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="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [ 123, 2]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what if the length of an array equals 4, and we try to "modify" the sixth element?&lt;/p&gt;

&lt;p&gt;JavaScript in this case is very liberal and allows us to shoot our own foot. The new element will be added into the array and the length will change.&lt;/p&gt;

&lt;p&gt;But there’s a surprise! Take a look:&lt;/p&gt;

&lt;p&gt;Same code with additional logging:&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;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&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="s1"&gt;Hello, world!&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [ 1, 2, 3, 4, &amp;lt;1 empty item&amp;gt;, 'Hello, world!' ]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;ANSWER&lt;/strong&gt;: The length of the array will change, and the number &lt;code&gt;6&lt;/code&gt; will be displayed on the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://js.coderslang.com" rel="noopener noreferrer"&gt;Learn Full-Stack JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
