<?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: Anthony Lopez</title>
    <description>The latest articles on DEV Community by Anthony Lopez (@aylolo).</description>
    <link>https://dev.to/aylolo</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%2F1068678%2Ff72b3164-10ec-4653-a3bf-696fc2f7d41e.jpg</url>
      <title>DEV Community: Anthony Lopez</title>
      <link>https://dev.to/aylolo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aylolo"/>
    <language>en</language>
    <item>
      <title>How To Use Tailwind CSS With React!</title>
      <dc:creator>Anthony Lopez</dc:creator>
      <pubDate>Wed, 19 Jul 2023 15:17:37 +0000</pubDate>
      <link>https://dev.to/aylolo/how-to-use-tailwind-css-with-react-1ph3</link>
      <guid>https://dev.to/aylolo/how-to-use-tailwind-css-with-react-1ph3</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Why this topic?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CSS can be quite a challenge for anyone new or experienced working on their front-end applications. It is one thing to code out a functioning, easy-to-use application but it is another story to have a application that is appealing to the eye. Unfortunately, the general public is subject to the practice of judging a book by it's cover and if the cover does not scream pretty, then the public loses interest. Software engineers can express their artistic visions through CSS but the how is always the question and the question can only find its answers through ones' tool. One of the tools that can help ease the pain and process of creating a design is Tailwind CSS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What is Tailwind CSS?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tailwind CSS is a utility-first CSS framework which makes it very easy to apply great styling to your React web application by choosing from the framework’s ready-made CSS classes. Tailwind CSS is quite popular among today's CSS frameworks and is used by known tech companies such as Twitch, Coursera, and Shopify. The approach that Tailwind CSS offers speeds up the styling process significantly and in setting up comprises only very few steps. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;THE TUTORIAL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Creating Your React Project&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Since React is the example that is being used today, the very first step will be creating a React project. The way to do is to use the &lt;code&gt;create-react-app&lt;/code&gt; script on the command line:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ npx create-react-app a-react-app-with-tailwind&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ cd react-app-with-tailwind&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The following output after running the &lt;code&gt;create-react-app&lt;/code&gt; script via the npx command should look something like this:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F72q8gl94566gm1apv7qs.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F72q8gl94566gm1apv7qs.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Install Tailwind CSS&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After having entered the newly created project folder &lt;code&gt;a-react-app-with-tailwind&lt;/code&gt;, we can now add the Tailwind CSS library and it's dependencies &lt;code&gt;postcss&lt;/code&gt; and &lt;code&gt;autoprefixer&lt;/code&gt; by using NPM (Node Package Manager) in the following way:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ npm install -D tailwindcss postcss autoprefixer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Generate Configuration Files&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The next step is to create default configuration files for Tailwind in the project folder and in order to configure everything we need for Tailwind, we will need the following two configuration files:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;tailwind.config.js&lt;/em&gt;&lt;br&gt;
&lt;em&gt;postcss.config.js&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;These files can be generated by executing the following command in the project folder:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ npx tailwindcss init -p&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command, on top of creating the files, makes it so the default configuration structure is already available in said files.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Configure Path To Template Files&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Inside &lt;code&gt;tailwind.config.js&lt;/code&gt;, we need to specify the path to our React template. This can be done by adding the following configuration setting:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;module.exports = {&lt;br&gt;
**   content: [&lt;br&gt;
     "./src/**/*.{js,jsx,ts,tsx}",&lt;br&gt;
   ],**&lt;br&gt;
   theme: {&lt;br&gt;
     extend: {},&lt;br&gt;
   },&lt;br&gt;
   plugins: [],&lt;br&gt;
 }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Paths are configured as glob patterns, patterns that can expand a wildcard pattern into a list of pathnames that match a given pattern, which means it's easy to match all of the content files in a project without a ton of configuration. We use * to match anything except slashes and hidden files, and ** to match zero or more directories. The values between &lt;code&gt;{}&lt;/code&gt; are seperated by a comma to match against a list of options. In the example above, the setting is matching all files with a file extenstion of &lt;em&gt;js, jsx, ts, and tsx&lt;/em&gt; covered within the &lt;em&gt;src&lt;/em&gt; subfolder.&lt;/p&gt;

&lt;p&gt;An important thing to note is that these paths are relative to the root of your project, &lt;strong&gt;NOT&lt;/strong&gt; the &lt;code&gt;tailwind.config.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Add Tailwind Directives&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Lastly, add the following Tailwind CSS directives into file &lt;code&gt;index.css&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@tailwind base;&lt;br&gt;
@tailwind components;&lt;br&gt;
@tailwind utilities;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Having done that, we can now make use of Tailwind's CSS classes within our main React component in App.js.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;LET'S USE TAILWIND CSS!&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To see Tailwind CSS in action, let's replace any default code in &lt;code&gt;src/App.js&lt;/code&gt; with the following implemenatation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function App() {&lt;br&gt;
  return (&lt;br&gt;
    &amp;lt;div className="container mx-auto bg-gray-200 rounded-xl shadow border p-8 m-10"&amp;gt;&lt;br&gt;
      &amp;lt;p className="text-3xl text-gray-700 font-bold mb-5"&amp;gt;&lt;br&gt;
        Welcome!&lt;br&gt;
      &amp;lt;/p&amp;gt;&lt;br&gt;
      &amp;lt;p className="text-gray-500 text-lg"&amp;gt;&lt;br&gt;
        React and Tailwind CSS in action&lt;br&gt;
      &amp;lt;/p&amp;gt;&lt;br&gt;
    &amp;lt;/div&amp;gt;&lt;br&gt;
  );&lt;br&gt;
}&lt;br&gt;
export default App;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Start the development web server with the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ npm run start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and you should be able to see the following result in the browser:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8gtd3l1y0v9dwhiwlwzs.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8gtd3l1y0v9dwhiwlwzs.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the event that things did not go as smoothly as expected, Tailwind CSS has a dedicated website &lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;&lt;/a&gt; that can answer any complex or further questions. &lt;/p&gt;

&lt;p&gt;In the event that things did go smoothly, it is recommended to use &lt;a href="https://nerdcave.com/tailwind-cheat-sheet" rel="noopener noreferrer"&gt;&lt;/a&gt; as a reference guide to use Tailwind CSS in all of it's freedom. &lt;/p&gt;

&lt;p&gt;That being said, may Tailwind CSS be the proper paint and brush to help you paint out your front-end to match the vision for your application!&lt;/p&gt;

</description>
      <category>tailwindcss</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Controlling Data with Flask-SQLAlchemy: Validations vs Constraints</title>
      <dc:creator>Anthony Lopez</dc:creator>
      <pubDate>Sat, 01 Jul 2023 01:11:13 +0000</pubDate>
      <link>https://dev.to/aylolo/controlling-data-with-flask-sqlalchemy-validations-vs-constraints-219o</link>
      <guid>https://dev.to/aylolo/controlling-data-with-flask-sqlalchemy-validations-vs-constraints-219o</guid>
      <description>&lt;p&gt;&lt;em&gt;Why this topic?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the world of coding, one of the many core skills of a programmer consists of abilities in managing databases. In a previous post about data structures with Python, it was discussed the importance of one's understanding of code and how to correctly organize, manage, and store code to properly create the building blocks of software systems. To reiterate, database management refers to the actions one takes to manipulate and control data to meet necessary conditions throughout the entire data lifecycle. Database management requires one to have strong skills with data structures and algorithims. Understanding how to use this knowledge is critical, because it is what can lead to building software that is efficient and optimized.&lt;/p&gt;

&lt;p&gt;When creating databases, validating the data that goes in is a critical step in ensuring a smooth workflow. Without validators or constraints for the data that is being taken in, especially at the beginning of the process, it can create inconsistences and may influence the final results making them inaccurate. In order to prevent inaccuracies, one must check &lt;em&gt;quality&lt;/em&gt; of the data before it is processed. Validating data is essential in creating data that is consistent, accurate and complete, preventing loss of data and errors. Data validation can be easily overlooked but it is good practice to constantly check oneself with what data exactly is being inputted. Flask-SQLAlchemy offers two ways, constraints and validations, to validate the data that is being taken into the database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Constraints&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SQL are used to specify rules for the data in a table. In other words, limit the type of data that can go into a table. If there is any violation between the constraint and the data action, the action gets aborted and the data does not go into the table. There are multiple constraints in SQL and each have their own special rules. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NULLABLE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By default, a column in a table can hold null values. The constraint NULLABLE enforces a column to NOT accept NULL values if set to false. It ensures that the field will always have a value, which means no change can be made with this field unless a value has been added.&lt;/p&gt;

&lt;p&gt;NULLABLE is useful for creating data for objects that cannot exist without having a value in their fields. An example could be an object with a name attached.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person(db.Model):
    __tablename__ = 'persons'

    id = db.Column(db.Integer, primary_key=true)
    first_name = db.Column(db.Integer, nullable=false)
    last_name = db.Column(db.Integer, nullable=false)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, an instance of Person must always have a value in the fields of first_name and last_name. This is because nullable is set to false, which means that when creating a person, it cannot exist unless there is a first name and a last name value. Logically speaking, a person could not (or at least should not) exist unless the person has a first and last name. NULLABLE is a good way to ensure that in creating instances, that data is not lost or incomplete. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UNIQUE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When inputting data into databases, values can be often repeated when creating multiple instances of a class. However, with the UNIQUE constraint, it ensures that all values in a column are &lt;em&gt;different&lt;/em&gt; or rather reflective of the constraint's name, unique. &lt;/p&gt;

&lt;p&gt;UNIQUE constraints can be useful when creating data that has an attribute that seperates it from the rest of the instances. UNIQUE constraints can come in the form of names, or ID numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Mountain(db.Model)
    __tablename__ == 'mountains'

    id = db.Column(db.Integer, primary_key=true)
    name = db.Column(db.String, unique=True)
    country_of_origin = db.Column(db.String)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, an instance of Mountain will have the fields of id, name, and country of origin. However, when creating an instance of Mountain, unique is set to true in the field of name. What that means is that in every instance of Mountain, name must be unique from each other and that no instance of Mountain can have name be repeated (the same for id). This logically makes sense because globally known mountains would have unique names that seperate it's identity, outside of it's id (or identifcation number) from each other. Country of origin does not have a unique constraint because multiple mountains can have the same country of origin. UNIQUE is a good constraint to make sure that certain fields do not contain the same data or have its data repeated. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DEFAULT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There may be circumstances when inputting data, that certain fields may not have a specified value therefore would need a default in case. The DEFAULT constraint would be used to set a default for a value in a column.&lt;/p&gt;

&lt;p&gt;The DEFAULT constraint can be used in scenarios where fields of data can be expected to have a certain value unless specified otherwise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Worker(db.Model)
    __tablename__ = 'workers'

    id = db.Column(db.Integer, primary_key=true)
    name = db.Column(db.String)
    salary = db.Column(db.Integer, default = 50000)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, an instance of Worker would have the fields of id, name, and salary. Salary has a DEFAULT constraint in which the value would always be an integer of 50,000 unless there is an input stating otherwise. Logically, this would be okay because this is assuming that every entry level worker would have the same base salary coming into a company. The DEFAULT constraint can help avoid repetition of inputs when knowing a field would in most case scenarios have a repeating value. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Validators&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Validators is an alternate way of checking the integrity and security of the data that is being input server-side. SQLAlchemy has a built in helped method for using validations, validates().&lt;br&gt;
Validates() is set up as function, that can check data being input through fields via if statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String)
    password = db.Column(db.String)

@validates('username')
def validate_username(self, key, value):
    if not value:
        raise ValueError("Must have a username")
    return value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, a class of User has an id , username and password attached to it. Here @validates is checking the &lt;em&gt;value&lt;/em&gt; of username, hence why the function is labeled as validate_username. The if statement reads that if there no value in the field of username, then a error message will pop up alerting the user on the server-side that the field of username must have a value. In the event that there &lt;em&gt;is&lt;/em&gt; a value for username, then the instance of User will return the value that was input for username. Validators are a valuable method of checking if whether or not data is being input at all, and if so, does it meet the conditions to best fit the field. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;In Conclusion&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Having been introduced to validators and constraints, try to manipulate the data being input to your database to your liking and properly match up the data up to what the fields are expected to have. A developer must always check the integrity and security of the data of not just from the front-end but from the back-end as well. Inconsistencies can be the downfall of a database, and the workflow can be greatly hindered when not being able to managae data properly. Thus, one must always be in control of their data inputs so that the workflow of a project can be clean, concise and accurately produce the results that one would hope to achieve. By strengthing the handle over your databases, the stronger of handle you have over your code and projects. By staying in control, the more power you can demonstrate with your applications and ultimately achieve the purposes you set for your projects!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Resources&lt;/em&gt;&lt;br&gt;
&lt;a href="https://www.sigmoid.com/blogs/data-validation/#:%7E:text=Data%20validation%20provides%20accuracy%2C%20cleanness,as%20Excel%20creates%20better%20results"&gt;https://www.sigmoid.com/blogs/data-validation/#:~:text=Data%20validation%20provides%20accuracy%2C%20cleanness,as%20Excel%20creates%20better%20results&lt;/a&gt;.&lt;br&gt;
&lt;a href="https://www.w3schools.com/sql/sql_constraints.asp"&gt;https://www.w3schools.com/sql/sql_constraints.asp&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flask</category>
      <category>python</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Data Structures In Python : The Building Blocks Of Software Systems</title>
      <dc:creator>Anthony Lopez</dc:creator>
      <pubDate>Thu, 08 Jun 2023 22:35:48 +0000</pubDate>
      <link>https://dev.to/aylolo/data-structures-in-python-the-building-blocks-of-software-systems-p03</link>
      <guid>https://dev.to/aylolo/data-structures-in-python-the-building-blocks-of-software-systems-p03</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Why This Topic?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Traversing in the world of coding, a programmer should consistently strive to cultivate their skills and reinforce their knowledge by first understanding the what and why of code. Quite often the struggles that arise and serve as obstacles for a programmer are disguised as simple questions to doubt the reasoning and logic behind the purpose of writing their code. However, these obstacles can easily dissipate when one is armed with the knowledge of what they are dealing with. A common goal of a programmer would relate to their skills dealing with hardware. This could consist of abilities like database management, statistical analysis, and software knowledge. &lt;/p&gt;

&lt;p&gt;Database management refers to the actions one takes to manipulate and control data to meet necessary conditions throughout the entire data lifecycle. Database management requires one to have strong skills with data structures and algorithims. These skills compound the strength of a programmer and that is because data structures serves as one of the building blocks of large software systems. Understanding how to use this knowledge is critical, because it is what can lead to building software that is efficient and optimized.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Data Structures In Python&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Organizing, managing, and storing data is more than what's likely to be expected from a programmer. However, with the existence of data structures, programmers can store collections of data, relate them and perform operations on them accordingly.&lt;/p&gt;

&lt;p&gt;Python has built-in support for data structures, and these structures are known as List, Dictionary, Set, and Tuple. Python also allows the programmer to create their own data structures. Data structures created by the programmer are commonly known as Stack, Queue, Tree, Linked List, Graph, and Hashmap. These data structures enable the programmer to have full control over the functionality of said structures. For today's subject, the focus will be on the built-in data structures of Python.&lt;/p&gt;

&lt;p&gt;Lists in Python are used to store data of different types in a sequential manner. Each element of the list is assigned an address, which is called an index. The value for the first element starts with an index of 0, then goes on and on until the very last element. This is known as positive index. On the flip side, there is negative index, where the value for the last element starts with -1, and goes on and on until the very first element. Let's take a look at an example of a list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = [] 
#this creates a empty list, or in other words, a list with no elements

my_list = ['duck', 'buck', 'goose'] 
#this creates a list of 3 elements
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since my_list has 3 elements, going by positive index, duck would have be at index 0, buck would be at index 1, and goose would be at index 2. Going by negative index, goose would be at index -1, buck would be at index -2 , and duck would be at index -3.&lt;/p&gt;

&lt;p&gt;To manipulate the data within the list, the append(), extend(), and insert() functions can be used. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Adding Elements&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = ['duck', 'buck', 'goose']
#this creates a list of 3 elements

my_list.append(['chick', 'chicken'])
#adds as a _single_ element

print(my_list)
['duck', 'buck', 'goose', ['chick', 'chicken']]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The append() function adds all the elements passed into it as a single element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = ['duck', 'buck', 'goose']
#this creates a list of 3 elements

my_list.extend(['hippo', 'lion'])
#adds as different elements

print(my_list)
['duck', 'buck', 'goose', 'hippo', 'lion'] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The extend() function adds the elements one-by-one into the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = ['duck', 'buck', 'goose']
#this creates a list of 3 elements

my_list.insert(2, 'bat')
#this adds the element starting from index 2

print(my_list)
['duck', 'buck', 'bat', 'goose']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The insert() function adds the element passed to the index value and increase the size of the list as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Deleting Elements&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In contrast, instead of adding data, the &lt;em&gt;del&lt;/em&gt; keyword, pop() function, remove() function and clear() function can delete data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = ['duck', 'buck', 'goose']
#this creates a list of 3 elements

del my_list[2]
#this deletes the element at index 2.

print(my_list)
['duck', 'buck']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;del&lt;/em&gt; keyword deletes the element passed to the index value and shortens the list as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = ['duck', 'buck', 'goose']
#this creates a list of 3 elements

v = my_list.pop(1)
#pops the element at index 1 and gives it back

print('Popped Element: ', v , 'List Remaining: ', my_list)
Popped Element: 'buck' List Remaining: ['duck', 'goose']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The pop() function takes the index value and gives the element back.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = ['duck', 'buck', 'goose']
#this creates a list of 3 elements

my_list.remove('goose')
#this deletes the element with the value taken in

print(my_list)
['duck', 'buck']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The remove() function takes a value and deletes the first occurence of the element with the matching value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = ['duck', 'buck', 'goose']
#this creates a list of 3 elements

my_list.clear()
#empties the list

print(my_list)
[]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The clear() function does not take any parameters, removes all elements from a list, and does not return anything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Accessing Elements&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Accessing elements in a list can be done by passing in the index values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = ['duck', 'buck', 'goose']
#this creates a list of 3 elements

print(my_list[2])
#access element at index 2
'goose'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;print(my_list[2])&lt;/code&gt;, is accessing the element that is at index 2 which in this case would be 'goose'.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Dictionary&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A dictionary in Python is used to store key-value pairs, where if the key is accessed, the values associated are also obtained. To create a dictionary in Python, the flower braces can be used or the dict() function. The key-value pairs must be added when working with dictionaries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_dict = {}
#creates an empty dictionary

my_dict = {'Mario' : 'Red', 'Luigi' : 'Green'}
#creates a dictionary with two key-value pairs

print(my_dict)
{'Mario':'Red','Luigi':'Green'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;my_dict&lt;/code&gt; has two key-value pairs. The first key-value pair has a key &lt;code&gt;'Mario'&lt;/code&gt; with the associated value of &lt;code&gt;'Red'&lt;/code&gt; whereas the second key &lt;code&gt;'Luigi'&lt;/code&gt; has the associated value of &lt;code&gt;'Green'&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Changing and Adding Key-Value pairs in Dictionaries&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the case of when dealing with dictionaries, changing the values can be done by acessing the keys. In other words, you must first access the key of a pair before you can change the value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_dict = {'Mario' : 'Red', 'Luigi' : 'Green'}
#creates a dictionary with two key-value pairs

my_dict['Luigi'] = 'Purple'
#access the pair with the matching key, then updates the value associated with it

print(my_dict)
{'Mario':'Red','Luigi':'Purple'}

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

&lt;/div&gt;



&lt;p&gt;Here, the key&lt;code&gt;'Luigi'&lt;/code&gt; is being passed into &lt;code&gt;my_dict&lt;/code&gt;, accessing  the key-value pair with the matching key and then changing the value from &lt;code&gt;'Green'&lt;/code&gt; to &lt;code&gt;'Purple'&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_dict = {'Mario' : 'Red', 'Luigi' : 'Green'}
#creates a dictionary with two key-value pairs

my_dict['Wario'] = 'Yellow'
#creates a new key-value pair 

print(my_dict)
{'Mario':'Red', 'Luigi':'Green','Wario':'Yellow'}

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

&lt;/div&gt;



&lt;p&gt;Here, the key &lt;code&gt;Wario&lt;/code&gt; is being passed into &lt;code&gt;my_dict&lt;/code&gt; and because there is no existing key that matches it, will create one and then associate the value &lt;code&gt;Yellow&lt;/code&gt; to it. The new key-value pair gets added to &lt;code&gt;my_dict&lt;/code&gt; and now the dictionary has 3 key-value pairs.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Deleting Key-Value Pairs&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Similarly to lists, to delete key-value pairs, the pop() and clear() function can be used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_dict = {'Mario' : 'Red', 'Luigi' : 'Green'}
#creates a dictionary with two key-value pairs

v = my_dict.pop('Luigi')
#pops the value with the associated key 'Luigi' and gives it back

print('Value: ', v)
print('Dictionary: ', my_dict)

Value: Green
Dictonary: {'Mario': 'Red'}

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

&lt;/div&gt;



&lt;p&gt;Here, the value is being returned by accessing the key of &lt;code&gt;Luigi&lt;/code&gt; in &lt;code&gt;my_dict&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_dict = {'Mario' : 'Red', 'Luigi' : 'Green'}
#creates a dictionary with two key-value pairs

my_dict.clear()
#empties the dictionary

print(my_dict)
{}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the clear() function does not take any parameters, deletes all key-pair values from the dictonary, and does not return anything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Tuple&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tuples are the same as lists but have the special rule that once the data has entered in the tuple, it cannot be changed no matter the circumstance. However, the exception to that rule is that if the data inside the tuple is mutable, then the tuple data can be changed. To create a tuple, parenthesis are used or the tuple() function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_tuple = (1, 7, 9, 4)
#creates a tuple with 4 elements

print(my_tuple)
(1, 7, 9, 4)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_tuple = (1, 7, 9, 4)
#creates a tuple with 4 elements

my_tuple = my_tuple + (0, 2)
#adds elements to the tuple

print(my_tuple)
(1, 7, 9, 4, 0, 2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To append elements to an existing tuple, the '+' operator can take another tuple to be appended to it.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Sets&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sets are a colleciton of unordered elements that are unique, meaning that the elements can be repeated more than one time but will enter the set only once. Sets are created using flower braces where values are only passed into it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_set = {2, 2, 2, 3, 3, 4, 5, 10}
#this creates a set

print(my_set)
{2, 3, 4, 5, 10}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, despite that &lt;code&gt;my_set&lt;/code&gt; has repeating elements, &lt;code&gt;my_set&lt;/code&gt; is printed with 5 elements only. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Adding Elements to Sets&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To add elements to sets, a value is passed to the add() function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_set = {2, 2, 2, 3, 3, 4, 5, 10}
#this creates a set

my_set.add(9)
#adds an element to the set

print(my_set)
{2, 3, 4, 5, 10, 9}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the add() function added a &lt;em&gt;unique&lt;/em&gt; element to the set, and since it is unique, is entered to the set.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Conclusion&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now having been introduced to built-in data structures in Python, create a space for yourself to work with data you are familiar with and get comfortable with manipulating data. Organizing, managing and storing data are a collection of skills that can be cultivated through trial and effort in a programmer's career. It is neccessary to have a solid understanding and handling of data, since data is what ultimately powers AI and advanced data applications. Remember to consistently check yourself with what you are doing with your code, and why you are writing your code. Knowledge is power, and with new-found knowledge, you can dispel your doubts and take one step closer to paving your path into the world of software engineering!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Resources&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.edureka.co/blog/data-structures-in-python/#:%7E:text=Organizing%2C%20managing%20and%20storing%20data,perform%20operations%20on%20them%20accordingly"&gt;https://www.edureka.co/blog/data-structures-in-python/#:~:text=Organizing%2C%20managing%20and%20storing%20data,perform%20operations%20on%20them%20accordingly&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/codewithshan/13-reasons-to-learn-data-structures-and-algorithms-2022-bbl#:%7E:text=Data%20structures%20and%20algorithms%20are%20the%20building%20blocks%20of%20large,you%20smarter%20as%20a%20programmer"&gt;https://dev.to/codewithshan/13-reasons-to-learn-data-structures-and-algorithms-2022-bbl#:~:text=Data%20structures%20and%20algorithms%20are%20the%20building%20blocks%20of%20large,you%20smarter%20as%20a%20programmer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.indeed.com/career-advice/career-development/career-goals-software-engineer#:%7E:text=Software%20engineers%20design%20and%20develop,are%20skilled%20in%20both%20areas"&gt;https://www.indeed.com/career-advice/career-development/career-goals-software-engineer#:~:text=Software%20engineers%20design%20and%20develop,are%20skilled%20in%20both%20areas&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>python</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The Power Of Components in React and staying DRY</title>
      <dc:creator>Anthony Lopez</dc:creator>
      <pubDate>Fri, 12 May 2023 17:11:29 +0000</pubDate>
      <link>https://dev.to/aylolo/the-power-of-components-in-react-and-staying-dry-57h0</link>
      <guid>https://dev.to/aylolo/the-power-of-components-in-react-and-staying-dry-57h0</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Why this topic?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A beginner practicing and using Javascript in the world of coding may have heard of React. Before diving into React, it is important to have a basic understanding of what Javascript is. Javascript is a widely used programming language used to build out web applications and works well across all web browsers. As Javascript was being practiced and it's popularity increasing, the Javascript community recognized patterns of code that were being repeated to accomplish the same tasks.&lt;/p&gt;

&lt;p&gt;A software engineer wants to uphold the principle of being DRY( Don't Repeat Yourself), and in the process of staying DRY, the development of Javascript libraries and frameworks came about from rewriting these repeated patterns of code. What Javascript libraries offered was that instead of writing these common patterns of code, code snippets were used to automate reoccuring animations and interactive forms that appeared on website applications. These prewritten code snippets were used and reused to perform common Javascript functions, and these Javascript librares were collections of said prewritten code snippets. Javascript librares were beneficial because it led to faster development of web applications that were less vulnerable to errors. React is one of these Javascript libraries and will be the focus of this discussion. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;What is React?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As mentioned before, ReactJS is a Javascript library and it's speciality lies in helping developers build user interfaces (UI's for short). React is a popular, if not, THE most popular Javascript library being used by large and famous companies all around over the world such as Uber, Amazon, Instagram and much more. It's worldwide use has promoted lots of growth in the developing community, despite it only have being in 2011 by Facebook. React libraries help developers build rich, efficent front-end abstractions with less code and less time as well. To expand, ReactJS is a web-component based library and an open source Javascript framework that enables developers to manipulate each state of the Javascript application to have it appear simple in a visual manner. When there is a change in state or data of the Javascript application, React effeciently updates and renders the right components hence why these abstractions require less code and save more time. Javascript libraries can use and reuse the same lines of code and React is no different in where React would reuse and recycle different components across the web application. These components can be made up of navigation bars, headers, forms, buttons and the like. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Calling Components&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To appreciate the value of using React, it is important to get comfortable with it's most important basic which is the &lt;em&gt;Component&lt;/em&gt;. React can be described as a lump of components, and that lump can call on other smaller lumps of components. Since the components can call on each other, component abstraction can be used for any level of detail. &lt;/p&gt;

&lt;p&gt;Let's look at an example of React at work &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2XPpcMoN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/164dfzz9cl11o3jrfvlp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2XPpcMoN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/164dfzz9cl11o3jrfvlp.png" alt="Image description" width="609" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, there is a button that has the name of "My Button". This particular button has an event handler that needs to be used multiple times. With the power of React and manipulating components, the MyButton component can be reused again throughout our main application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GBBuNxV5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tm1kk9t1ouwh591f14lo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GBBuNxV5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tm1kk9t1ouwh591f14lo.png" alt="Image description" width="343" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As seen above, the main component has a name of "My Main". This particular main component is returning a main element, and within this main element are three paragraph elements that each contain the MyButton component. What this means is that the code for the MyButton component is being reused not once, not twice, but three times in each of our paragraph elements that are being contained within the Main component. To further provide example of being able to reuse components in React, the code for Main component will finally be then reused in the App component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wq-IdfdF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/esxzv1awrlt47l34c0bw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wq-IdfdF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/esxzv1awrlt47l34c0bw.png" alt="Image description" width="223" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The App component from above is returning a div element that contains the reused code for the Main component. Through the power of components, using code and reusing code is more efficent and saves the trouble of having to rewrite code which can be prone to having errors and helps the developer in staying DRY. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Conclusion&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A software engineer's common goal should be in always trying to improve their personal code writing skills. In order to do that, it is important to uphold the principle of keeping DRY. React does an effecient job in helping the developer in keeping DRY through the use and reuse of components. However, React is a beast of it's own and has it's own personal rules that it abides to. It is strongly encouraged to take a deep dive into React and understand the specifics as how components can transform web-based applications. Of course, a challenge that can always be recommended is to take on a project using said language or library. A particular strength of a software engineer lies in their code writing and as always, it is important to take your steps towards keeping DRY!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Resources&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://legacy.reactjs.org/docs/components-and-props.html"&gt;https://legacy.reactjs.org/docs/components-and-props.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://generalassemb.ly/blog/what-is-a-javascript-library/"&gt;https://generalassemb.ly/blog/what-is-a-javascript-library/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.knowledgehut.com/blog/web-development/reasons-to-learn-reactjs"&gt;https://www.knowledgehut.com/blog/web-development/reasons-to-learn-reactjs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Javascript : The Importance of the forEach() Method</title>
      <dc:creator>Anthony Lopez</dc:creator>
      <pubDate>Tue, 25 Apr 2023 17:11:12 +0000</pubDate>
      <link>https://dev.to/aylolo/javascript-the-importance-of-the-foreach-method-pba</link>
      <guid>https://dev.to/aylolo/javascript-the-importance-of-the-foreach-method-pba</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;Why This Topic?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For beginners and experts alike, learning a new topic in the field of programming can be quite challenging. It may vary from person to person, but it takes a significant amount of time and effort in order to read, understand, and then use the new material in practice. On top of that, programmers all code differently, and have their own approach, practices and intentions when using said material. For the learning individual, there is &lt;em&gt;a lot&lt;/em&gt; of information to intake and thus, can be hard to draw up a starting point. &lt;/p&gt;

&lt;p&gt;As like all things, there are golden rules to keep and follow when writing code. These rules consist of following a standard, naming things properly, and being expressive while also avoiding writing god objects and long methods. One particular rule that arguably should be highlighted, stresses that the coder must stay &lt;em&gt;DRY&lt;/em&gt;. Being DRY is a software engineering principle which stands for 'Don't repeat yourself'. This principle aims at reducing the repetition of patterns and code duplication, so that the final product would look clean and concise by avoiding redundancy.&lt;/p&gt;

&lt;p&gt;But how does one stay DRY? In coding, there is no one distinct way to meet the solution to a problem. One solution can be found in thousands of  lines of code, and others can be found as short as maybe hundreds. For beginners especially, it is quite the challenge to find the most optimal route to meet their end goal. When working with arrays, especially those with an obscene amount of values, the beginner may feel taunted to repeat the same lines of code for each and every value in the array. However, that does not have to be the case with the &lt;strong&gt;forEach()&lt;/strong&gt; method available!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;But what is the forEach() method? What does it do?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When learning programming, it is important to read, understand, and then being able to write code. Like writing or speaking a language, it is important to convey concisely what it is that the user wants the computer to do. First thing, the syntax for the &lt;code&gt;forEach()&lt;/code&gt;method is &lt;code&gt;forEach(callbackFn)&lt;/code&gt;. The forEach() method executes a provided function once for each array element. In other words, it is an iterative method that calls a provided &lt;code&gt;callbackFn&lt;/code&gt; once for each element in the array in ascending-index order. Basically, we take each element in the array as an input for the &lt;code&gt;callbackFn&lt;/code&gt; and have said &lt;code&gt;callbackFn&lt;/code&gt; perform its task or calculate the value &lt;em&gt;for each&lt;/em&gt; input. Hence, it can be understood why it is literally called the forEach() method.&lt;/p&gt;

&lt;p&gt;Let's look at an example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Nbo3vn8X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2mmauyebkusa6hiqudr8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Nbo3vn8X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2mmauyebkusa6hiqudr8.png" alt="Image description" width="595" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above, an array is being identified as &lt;code&gt;colors&lt;/code&gt; that contains three elements consisting of &lt;code&gt;'red'&lt;/code&gt;, &lt;code&gt;'blue'&lt;/code&gt;, and '&lt;code&gt;yellow'&lt;/code&gt;. For each of these elements, a message is being output to the console (&lt;code&gt;console.log()&lt;/code&gt;). However, there is a way to avoid these lines of repetition and be able to &lt;code&gt;console.log()&lt;/code&gt; each element with less lines of code.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Example Code&lt;/strong&gt;&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6QFp6hhy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jct77j30vf95nopxtvz5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6QFp6hhy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jct77j30vf95nopxtvz5.png" alt="Image description" width="597" height="218"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Again, here the &lt;code&gt;const colors&lt;/code&gt; is being identified as an array. This array has three elements(&lt;code&gt;'red'&lt;/code&gt;, &lt;code&gt;'blue'&lt;/code&gt;, and &lt;code&gt;'yellow'&lt;/code&gt;), each one being identified as a 'color'. Using the &lt;code&gt;forEach()&lt;/code&gt; method, the function will take each &lt;code&gt;color&lt;/code&gt; as an input then &lt;code&gt;console.log()&lt;/code&gt; each &lt;code&gt;color&lt;/code&gt; in the array of the const &lt;code&gt;colors&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Even in the example of if &lt;code&gt;colors&lt;/code&gt; had 1000 elements in the array, the &lt;code&gt;forEach()&lt;/code&gt; method would take each of those elements, and execute the provided function. In that scenario, the &lt;code&gt;forEach()&lt;/code&gt; would save a significant amount of time by avoiding repeating the same lines of code for each element, and by avoiding repetition, the coder can stay DRY!&lt;/p&gt;

&lt;p&gt;However, there are some notes to be aware of on the &lt;code&gt;forEach()&lt;/code&gt;&lt;br&gt;
method. A specific note to be discussed is the &lt;code&gt;callbackFn&lt;/code&gt; can only invoked in array indexes that have assigned values. The &lt;code&gt;callbackFn&lt;/code&gt; will NOT be invoked for empty slots in sparse arrays.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--up1ErGDn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdytg0u25bk74kkkubb3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--up1ErGDn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdytg0u25bk74kkkubb3.png" alt="Image description" width="595" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, there is a missing value for &lt;code&gt;colors&lt;/code&gt; at index 2. The invoked function still takes the inputs for all assigned values but will not be invoked for the empty value at index 2. &lt;/p&gt;

&lt;p&gt;Another note on the &lt;code&gt;forEach()&lt;/code&gt; method is that while the &lt;code&gt;forEach()&lt;/code&gt; method does NOT mutate the array that which it is called, the function provided as &lt;code&gt;callbackFN&lt;/code&gt; CAN. However, modifications of the array through that method lead to hard-to-understand code and should be avoided in general cases. That being said, there are many other notes to be explored on the &lt;code&gt;forEach()&lt;/code&gt; method but for now, this should be enough information to put this method in practice!&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;forEach()&lt;/code&gt; method is valuable when it comes to staying DRY, and it is strongly encouraged that when possible, keep your code simple and clean. So the next time you find yourself repeating the same lines of code over and over again, ask yourself 'Can the &lt;code&gt;forEach&lt;/code&gt; method be used?', and with your answer hopefully you'll be one more step closer to staying DRY!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;a href="https://www.digitalocean.com/community/tutorials/what-is-dry-development"&gt;https://www.digitalocean.com/community/tutorials/what-is-dry-development&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.yipl.com.np/7-golden-rules-of-simple-and-clean-code-and-some-more-considerations-slides-e66662af2daf"&gt;https://blog.yipl.com.np/7-golden-rules-of-simple-and-clean-code-and-some-more-considerations-slides-e66662af2daf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#syntax"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#syntax&lt;/a&gt;&lt;/p&gt;

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