<?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: allyn</title>
    <description>The latest articles on DEV Community by allyn (@allyn).</description>
    <link>https://dev.to/allyn</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%2F1123553%2F23eaf3ca-d618-4bda-b19b-9959b566cd0b.png</url>
      <title>DEV Community: allyn</title>
      <link>https://dev.to/allyn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/allyn"/>
    <language>en</language>
    <item>
      <title>Vue.js</title>
      <dc:creator>allyn</dc:creator>
      <pubDate>Sun, 23 Jun 2024 20:40:45 +0000</pubDate>
      <link>https://dev.to/allyn/vuejs-ffg</link>
      <guid>https://dev.to/allyn/vuejs-ffg</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Vue.js is a JavaScript framework used for creating user interfaces. Using Vue.js, you can create components to efficiently build your program and enhance HTML with the template syntax provided that reflects the state of your component. When your state changes, Vue will automatically update the DOM upon said change. Let's go over the basics.&lt;/p&gt;

&lt;p&gt;There are many ways to create components for your Vue projects and one way to do it is to develop single-file components, or SFCs. These SFCs contain all of the logic for the component with JS, the template with HTML, and the styling with CSS all in the same file. Vue SFCs use a &lt;code&gt;*.vue&lt;/code&gt; file extension and are the &lt;a href="https://vuejs.org/guide/introduction.html#single-file-components"&gt;recommended way to create Vue components&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting your Vue application
&lt;/h2&gt;

&lt;p&gt;All Vue applications start out with an application instance that you get from invoking the &lt;code&gt;createApp&lt;/code&gt; function. The &lt;code&gt;createApp&lt;/code&gt; function takes an object for an argument that will be the root component of the application. Normally with SFCs, you can import the component you intend to have as your root component, and you pass that as your argument to &lt;code&gt;createApp&lt;/code&gt;, similarly to how one would with an application using React.&lt;/p&gt;

&lt;h2&gt;
  
  
  Viewing your Vue application
&lt;/h2&gt;

&lt;p&gt;Once you have your application instance, you'll need to be able to view your application. To do this, Vue provides the &lt;code&gt;mount&lt;/code&gt; method that renders your application instance. The &lt;code&gt;mount&lt;/code&gt; method's argument will either be a selector string or a DOM element, and the root component will be rendered inside the argument. One of the caveats of the &lt;code&gt;mount&lt;/code&gt; method is that you should only invoke it once your application is totally configured and assets are fully registered.&lt;/p&gt;

&lt;h2&gt;
  
  
  The application instance
&lt;/h2&gt;

&lt;p&gt;The application instance is more than just a return value of &lt;code&gt;createApp&lt;/code&gt;; it allows you to add functionality across your entire application. One of the perks of the application instance is the &lt;code&gt;config&lt;/code&gt; object that allows you to set up &lt;a href="https://vuejs.org/guide/essentials/application.html#app-configurations"&gt;"app-level options"&lt;/a&gt;, and the application instance provides a way to create assets for your application. As mentioned before, any assets or additional functionality you want to provide to your application must be done before mounting the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Templating
&lt;/h2&gt;

&lt;p&gt;Vue templates are based on HTML and are comparable to AngularJS templates in how they "extend" the HTML syntax and are used to reflect the component's data to the client. Behind the scenes, Vue compiles the templates figures out the fewest components needed for a re-render, and manipulates the DOM on app state changes as minimally as possible. &lt;/p&gt;

&lt;p&gt;For developers who like to use JSX in their applications, Vue supports JSX. You can write render functions with JSX instead of templates, however, you run the risk of compromising the compile-time of your components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Binding
&lt;/h2&gt;

&lt;p&gt;There are 2 forms of data binding in Vue: text interpolation and attribute bindings. Text interpolation, or "Mustache syntax", in Vue uses double curly braces in between HTML tags. The data inside the double curly braces will be interpreted and evaluated in plain text. Attribute bindings are used with the &lt;code&gt;v-bind&lt;/code&gt; directive. The &lt;code&gt;v-bind&lt;/code&gt; directive takes an argument, likely an HTML attribute, and will bind the value of that attribute to the component's specified property or any other specified value. &lt;/p&gt;

&lt;h2&gt;
  
  
  Directives
&lt;/h2&gt;

&lt;p&gt;Directives are used to apply updates to the DOM and add special behavior to DOM elements. These directives are put inside the DOM element with the attributes and are prefixed with &lt;code&gt;v-&lt;/code&gt;. Directives can perform a number of different operations, like looping, registering event handlers, updating HTML text, and many more. The syntax for a directive looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;element v-directive:argument="value" &amp;gt; ... &amp;lt;/element&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Vue also provides syntactic sugar for their &lt;code&gt;v-bind&lt;/code&gt; and &lt;code&gt;v-on&lt;/code&gt; directives. The shorthand syntax for &lt;code&gt;v-bind&lt;/code&gt; lets you omit &lt;code&gt;v-bind&lt;/code&gt; and only use the colon with the argument and its value following right after.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;element :argument="value"&amp;gt; ... &amp;lt;/element&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or if you have the argument has the same name as the value it is being bound to, you also can shorten the directive even more.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;element :argument&amp;gt; ... &amp;lt;/element&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;v-on&lt;/code&gt; directive is used to register event handlers to DOM elements and the shorthand for &lt;code&gt;v-on&lt;/code&gt; uses the &lt;code&gt;@&lt;/code&gt; instead of the colon to come before arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;element @argument&amp;gt; ... &amp;lt;/element&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You have probably noticed by now that the arguments for these directives are static, but Vue provides a way for you to use dynamic arguments. These arguments are still prefixed by the colon but are wrapped in square brackets, and they come with a couple of constraints. Dynamic arguments are supposed to evaluate either to a string or null; if the argument is evaluated as null, this can remove your binding. Also, even if your argument evaluates to a string, the string must be able to be a valid HTML attribute, since that is what the argument of directives is, meaning using some characters will throw warnings. You should also be mindful of the casing of your dynamic argument because the browser will adjust the casing behind the scenes and the code will not work as you expect.&lt;/p&gt;

&lt;p&gt;Vue allows you to customize your directives with modifiers that specify how the directive should be bound. Modifiers are attached to the directives argument with a dot.&lt;/p&gt;

&lt;p&gt;This encapsulates the complete directive syntax for Vue applications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;element v-directive:argument.modifier="value"&amp;gt; ... &amp;lt;/element&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Vue provides lifecycle hooks as well for your application. These hooks cover the basic parts of the lifecycle, mounting, updating, unmounting, and since all Vue applications aren't server-side applications, there are hooks for other use cases of Vue.&lt;/p&gt;

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

&lt;p&gt;Vue provides a streamlined way to create dynamic and interactive user interfaces for applications and I look forward to using Vue in the future.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Prisma ORM</title>
      <dc:creator>allyn</dc:creator>
      <pubDate>Sun, 09 Jun 2024 20:08:19 +0000</pubDate>
      <link>https://dev.to/allyn/prisma-orm-kjh</link>
      <guid>https://dev.to/allyn/prisma-orm-kjh</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Prisma ORM is an open-source ORM made up of 3 parts: Prisma Client, Prisma Migrate, and Prisma Studio. Prisma Client is an auto-generated, type-safe database client for Node.js and TypeScript. Prisma Migrate is a migration system, and Prisma Studio is an interface to view and manipulate data in the database. As an ORM, Prisma ORM supports databases like MongoDB, PostreSQL, MySQL, and &lt;a href="https://www.prisma.io/docs/orm/reference/supported-databases"&gt;many more&lt;/a&gt;. Upon installation of Prisma, you have access to the Prisma CLI, which is how you will mainly interact with your Prisma project. All Prisma projects start off with a schema before any of the main components are utilized, so let's start with the Prisma schema.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prisma Schema
&lt;/h2&gt;

&lt;p&gt;We know that Prisma is not a database, but an ORM, which is a tool to "translate" the data in the database to the developer. We also know that Prisma supports many different databases, which vary in syntax and structure/architecture. This is where the Prisma schema comes in. &lt;/p&gt;

&lt;p&gt;Your Prisma schema, made up of models, reflects your database schema and acts as a proxy database. These schemas are written inside a &lt;code&gt;schema.prisma&lt;/code&gt; file and contain a connection to the database via &lt;code&gt;datasource&lt;/code&gt; and a &lt;code&gt;generator&lt;/code&gt; that &lt;a href="https://www.prisma.io/docs/orm/overview/introduction/what-is-prisma#the-prisma-schema"&gt;'indicates that you want to generate a Prisma Client'&lt;/a&gt;. Data models take up the most space in the Prisma schema because they represent the tables or collections in databases, and they act as the base of the Prisma Client. Prisma gives you 2 workflows to create these models: Prisma Migrate and introspection. &lt;/p&gt;

&lt;h3&gt;
  
  
  Introspection
&lt;/h3&gt;

&lt;p&gt;Introspection is defined as a &lt;a href="https://en.wikipedia.org/wiki/Type_introspection"&gt;"program's ability to examine the type or properties at run time"&lt;/a&gt;. In the context of Prisma, introspection is when the program reads your database schema and generates your Prisma schema based on your database schema. Introspection is commonly used for an initial version of the Prisma schema, however, it can be used repeatedly, mainly when Prisma Migrate is not being used. If there are any changes to either schema, you can use introspection to ensure that both your database schema and Prisma schema are congruent. The workflow using introspection uses commands like &lt;code&gt;prisma db pull&lt;/code&gt; and &lt;code&gt;prisma db push&lt;/code&gt; that allow for said congruency in your project.&lt;/p&gt;

&lt;p&gt;The workflow for introspection will follow, &lt;a href="https://www.prisma.io/docs/orm/prisma-schema/introspection"&gt;per Prisma's documentation&lt;/a&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjbr361baob9upv8xt5gz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjbr361baob9upv8xt5gz.png" alt="Image description" width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Prisma Migrate
&lt;/h2&gt;

&lt;p&gt;Prisma Migrate is used to synchronize your Prisma schema and database schema as either one evolves. One of the main uses of Prisma Migrate is to ensure updates to your Prisma schema are reflected in your database schema, and this is done by using the &lt;code&gt;migrate&lt;/code&gt; commands from the Prisma CLI. The objective of the commands under the Prisma Migrate umbrella of the Prisma CLI is to apply and resolve migrations, or updates, to the Prisma schema. Also as a result of creating a migration, SQL migration files are generated which act as a documented history of changes to the schema. &lt;/p&gt;

&lt;p&gt;Let's look at the &lt;code&gt;prisma migrate dev&lt;/code&gt; command which will be one of the main &lt;code&gt;prisma migrate&lt;/code&gt; commands. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;prisma migrate dev&lt;/code&gt; command will rerun the existing migration history on a "shadow database" to detect schema drift, which are changes and deletions of migration files or changes made directly to the database schema. The shadow database is a second, temporary database used to detect issues in your migrations. Shadow databases have a lifespan of however long the &lt;code&gt;prisma migrate dev&lt;/code&gt;, meaning they are created every time the command is run and is deleted once the command is complete. Pending migrations are applied and thus generate a new migration file, documenting what changes were made to the database and warnings if applicable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*
  Warnings:

  - You are about to drop the column `artistId` on the `Album` table. All the data in the column will be lost.
  - You are about to drop the column `name` on the `Album` table. All the data in the column will be lost.
  - Added the required column `albumName` to the `Album` table without a default value. This is not possible if the table is not empty.
  - Added the required column `artistName` to the `Album` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE `Album` DROP FOREIGN KEY `Album_artistId_fkey`;

-- AlterTable
ALTER TABLE `Album` DROP COLUMN `artistId`,
    DROP COLUMN `name`,
    ADD COLUMN `albumName` VARCHAR(191) NOT NULL,
    ADD COLUMN `artistName` VARCHAR(191) NOT NULL;

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

&lt;/div&gt;



&lt;p&gt;The code block above is an example of what a migration file consists of when you make changes to your schema.&lt;/p&gt;

&lt;p&gt;Once you're content with the state of your database and ready to add records to your database, you can move on to using Prisma Client.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prisma Client
&lt;/h2&gt;

&lt;p&gt;Prisma Client is your database client built on your Prisma schema and is how you make queries to your database. In order to use your Prisma Client, you must run the &lt;code&gt;prisma generate&lt;/code&gt; command in your terminal. after you run &lt;code&gt;prisma generate&lt;/code&gt;, you should see this in your terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✔ Generated Prisma Client (v5.15.0) to ./node_modules/@prisma/client in 45ms

Start using Prisma Client in Node.js (See: https://pris.ly/d/client)

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

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

&lt;/div&gt;



&lt;p&gt;You will receive a block of code you can copy and paste into whichever files you will be making queries to your database. This also shows a peek into how user-friendly Prisma is. The &lt;code&gt;prisma generate&lt;/code&gt; command can also be used to solidify changes made to your database since this is how you'll interact with the data inside the database.&lt;/p&gt;

&lt;p&gt;This will be put at the top of your file where you'll be making queries, with the rest of the import statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server/index.ts
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you import your Prisma Client, you can now make queries with the &lt;code&gt;prisma&lt;/code&gt; variable. The syntax for making queries is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prisma.&amp;lt;model&amp;gt;.&amp;lt;queryMethod&amp;gt;({})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;According to Prisma's documentation, &lt;a href="https://www.prisma.io/docs/orm/overview/introduction/what-is-prisma#accessing-your-database-with-prisma-client"&gt;"all Prisma Client queries return plain old JavaScript objects"&lt;/a&gt;, but these queries can be made asynchronous with async/await or using Promise methods like &lt;code&gt;.then()&lt;/code&gt; and &lt;code&gt;.catch()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prisma Studio.
&lt;/h2&gt;

&lt;p&gt;Prisma Studio is a "graphical user interface for you to view and edit your database" in the browser. It's important to note that Prisma Studio is not open-source.&lt;/p&gt;

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

&lt;p&gt;Prisma ORM is a highly flexible and type-safe tool that makes interacting with your data in the database more transparent and streamlined for developers.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Step into TypeScript (part 1)</title>
      <dc:creator>allyn</dc:creator>
      <pubDate>Mon, 27 May 2024 04:03:01 +0000</pubDate>
      <link>https://dev.to/allyn/step-into-typescript-part-1-10dg</link>
      <guid>https://dev.to/allyn/step-into-typescript-part-1-10dg</guid>
      <description>&lt;p&gt;Continuing my exploration of JavaScript has led me into the world of TypeScript. TypeScript is a free, open-source, typed programming language that is a superset of JavaScript.&lt;/p&gt;

&lt;p&gt;TypeScript was released in October 2012 with version 0.8 and developed by Microsoft. A superset of JavaScript, TypeScript knows JavaScript and adds additional syntax to make a more fortified application. Also, being built on JavaScript, TypeScript can be transpiled into JavaScript and perform type inference so you do not have to add any additional code. Type inference is defined as "the ability to deduce, either partially or fully automatically, the type of an expression at compile time," with 'type' referring to data types (i.e. 'string', 'number', etc.).&lt;/p&gt;

&lt;p&gt;TypeScript focuses highly on data types, hence the name and enhanced syntax and features we will go over. One of these features is defining types with interface declaration. Interfaces, in TypeScript, act as contracts that enforce consistent assignment of types. Interface declaration can be compared to JavaScript's subclassing, in the sense that you establish the structure and/or type of something. All of your JavaScript code will not always be inferred, so you use interfaces to ensure that TypeScript knows what values are to be expected. Let's take a look at an example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html"&gt;These examples are provided by TypeScript's documentation.&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = {
  name: "Allyn",
  id: 0,
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have an object called &lt;code&gt;user&lt;/code&gt; that has properties of &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt;. The properties of &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt; can be inferred as a string and number respectively, but there's a way to enforce that these properties are consistently strings and numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface User {
  name: string;
  id: number;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using interface declaration, you can ensure that &lt;code&gt;name&lt;/code&gt; will always be a string and &lt;code&gt;id&lt;/code&gt; a number. Think of this &lt;code&gt;User&lt;/code&gt; interface as a blueprint for &lt;code&gt;user&lt;/code&gt; objects. To make sure that JavaScript follows this blueprint, we create an 'instance' of a type by adding &lt;code&gt;: TypeName&lt;/code&gt; in between the variable name and the assignment operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user: User = {
  name: "Allyn",
  id: 0,
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From a JavaScript perspective, this is comparable to subclassing. In fact, you can use interface declaration for classes too, since both JavaScript and TypeScript support classes. &lt;/p&gt;

&lt;p&gt;TypeScript can use primitive JavaScript data types in interfaces, which include: booleans, null, and undefined. TypeScript adds to this list with types like &lt;code&gt;any&lt;/code&gt;, &lt;code&gt;never&lt;/code&gt;, and &lt;code&gt;void&lt;/code&gt;. The &lt;code&gt;any&lt;/code&gt; type is to signify that there aren't any restrictions to what type can be assigned, the &lt;code&gt;never&lt;/code&gt; type is to determine what type will never be assigned, and the &lt;code&gt;void&lt;/code&gt; type is used for having no type at all, undefined, and is commonly used in the context of function return values.&lt;/p&gt;

&lt;p&gt;Out of the box, TypeScript uses primitive data types, but what about complex data types such as collections? Fortunately, TypeScript allows you to create your own type. The 2 most popular ways to create types are with unions, which can be recognized with a pipe &lt;code&gt;|&lt;/code&gt;, or with generics, following this syntax: &lt;code&gt;&amp;lt;variable&amp;gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Unions can be used when a type can be one out of many types and are commonly used for defining options out of a set. In this example, &lt;code&gt;color&lt;/code&gt; can be one out of many colors, and &lt;code&gt;spice&lt;/code&gt; can be one of many numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ColorOptions = "green" | "yellow" | "pink" | "black";
const SpiceOptions = 1 | 3 | 5 | 7;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generics act as variables for types and are commonly used to describe what type an array contains. For example, this &lt;code&gt;NamesArray&lt;/code&gt; will consist of strings. Take note of the &lt;code&gt;type&lt;/code&gt; keyword that creates an alias for the type. In this case, &lt;code&gt;NamesArray&lt;/code&gt; is the alias for the array type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type NamesArray = Array&amp;lt;string&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;a href="https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html#generics"&gt;provided by the TypeScript documentation&lt;/a&gt;, you can use generics in conjunction with interfaces to create types that have a predetermined consistency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Backpack&amp;lt;Type&amp;gt; {
  add: (obj: Type) =&amp;gt; void;
  get: () =&amp;gt; Type;
}

// This line is a shortcut to tell TypeScript there is a
// constant called `backpack`, and to not worry about where it came from.
declare const backpack: Backpack&amp;lt;string&amp;gt;;

const object = backpack.get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go through this code line by line. We start off by creating a backpack interface that consists of 2 methods: add and get, both refer to the &lt;code&gt;Type&lt;/code&gt; variable that will be filled in later when the interface gets used. Next, our &lt;code&gt;backpack&lt;/code&gt; variable gets 'string' passed in, meaning the &lt;code&gt;obj&lt;/code&gt; is a string and the &lt;code&gt;get&lt;/code&gt; method returns a string since both refer to the &lt;code&gt;Type&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;From what we've gone over, we can see how essential data types are for TypeScript. We can see that the syntax follows closely to JavaScript but the use of the language shifts to hone on consistency and avoiding errors. In my next post, I will go over the Structural Type System, Classes, and how TypeScript can be compared to JavaScript.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Raspberry Pi</title>
      <dc:creator>allyn</dc:creator>
      <pubDate>Mon, 22 Apr 2024 01:26:15 +0000</pubDate>
      <link>https://dev.to/allyn/raspberry-pi-4bgd</link>
      <guid>https://dev.to/allyn/raspberry-pi-4bgd</guid>
      <description>&lt;p&gt;Increasing my time on the computer since learning software development has increased my curiosity about computers as a device. What makes a computer? How does a computer connect to the internet? What is the relationship between hardware and software? I came across Raspberry Pi and decided to explore what it is, how it is used, and what it is used for.&lt;/p&gt;

&lt;p&gt;Raspberry Pi is a series of single-board computers created by the Raspberry Pi Foundation. When I searched what a Raspberry Pi was, what I saw did not look like the computers I was familiar with. That's because single-board computers are fully functioning computers built on a single circuit board. These boards have a microprocessor, input-output functions, and memory built on as well as a predetermined amount of RAM (Random Access Memory). Raspberry Pi computers are built on Arm architecture, which describes the rules for how the hardware and software interact. In addition to the Arm architecture, Raspberry Pi also utilizes the Linux operating system and includes amenities like general-purpose input-output pins that allow you to &lt;a href="https://opensource.com/resources/raspberry-pi"&gt;"explore the Internet of Things"&lt;/a&gt;. IBM defines the Internet of Things as a "network of physical devices that have embedded sensors, software, and network connectivity that allow them to collect and share data". &lt;/p&gt;

&lt;p&gt;Since 2012, Raspberry Pi has 3 series of computers with varying generations. Most generations have 2 models: Model A and Model B; Model A is more affordable but has less RAM and ports. The first original Raspberry Pi computer only had 256 megabytes of RAM. The latest edition, Raspberry Pi 5, has a 4 GB RAM option and an 8 GB RAM option, both are twice as powerful as the Raspberry Pi 4. To put it into perspective, 4 GB or 8GB is sufficient for browsing the web and web processing, per &lt;a href="https://www.lenovo.com/us/en/glossary/how-much-memory-ram-do-i-need-on-my-laptop/?orgRef=https%253A%252F%252Fwww.google.com%252F"&gt;Lenovo&lt;/a&gt;, which is 15X more RAM than the original Raspberry Pi.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp519mrkl5ci2ihoos1pv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp519mrkl5ci2ihoos1pv.jpg" alt="Image description" width="440" height="365"&gt;&lt;/a&gt;&lt;br&gt;
Pictured above is an [early Raspberry Pi 1 Model A]. (&lt;a href="https://en.wikipedia.org/wiki/Raspberry_Pi"&gt;https://en.wikipedia.org/wiki/Raspberry_Pi&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nkxad6sc7yvt4hex8ie.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nkxad6sc7yvt4hex8ie.jpeg" alt="Image description" width="440" height="352"&gt;&lt;/a&gt;&lt;br&gt;
Pictured above is a &lt;a href="https://en.wikipedia.org/wiki/Raspberry_Pi"&gt;Raspberry Pi 5&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are many options for projects you can choose with your Raspberry Pi that can help you learn computer science, machine learning, and programming. A common project is to build your PC but you can turn devices into smart devices with the GPIO pins that give you access to the Internet of Things. However, there are more adventurous avenues to take with your computer. &lt;a href="https://www.pcworld.com/article/420028/10-practical-raspberry-pi-projects-anyone-can-do.html#:~:text=Affordable%20productivity%20PC,video%20streams%2C%20and%20document%20editing"&gt;Brad Chacos lists 10 projects you can do with your computer&lt;/a&gt;. You can set up a home-theater PC with the $35 original Raspberry Pi, and with the $21 TV accessory, you can read TV signals. Or you can turn your TV into a smart TV with Raspberry Pi 2 - 4, letting you browse the internet. Raspberry Pi computers are generally under $100, with the average being around $35, and the cheapest, Raspberry Pi Zero is $5, you don't burn holes in your pockets by investing in one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk8brlu9sw3vxuefv5jbi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk8brlu9sw3vxuefv5jbi.jpg" alt="Image description" width="400" height="199"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/Raspberry_Pi#Series_and_generations"&gt;Pictured above is the Raspberry Pi Zero, introduced in 2015&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Raspberry Pi's main supported operating system Pi OS (formerly known as Raspbian), is open-source and runs open-source software. If you're looking into programming your Raspberry Pi, Vibha Gupta lists programming languages that are better suited for it. The more popular options include, but are not limited to Python, C, and C++. But those of us who know JavaScript should fear not because Raspberry Pi supports JS and jQuery.&lt;/p&gt;

&lt;p&gt;In conclusion, the single-board computer Raspberry Pi has a ton of might and versatility and is something I would like to explore as a software developer who doesn't know much about the technology she uses daily!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>LeetCode</title>
      <dc:creator>allyn</dc:creator>
      <pubDate>Sun, 14 Apr 2024 04:25:15 +0000</pubDate>
      <link>https://dev.to/allyn/leetcode-1i2h</link>
      <guid>https://dev.to/allyn/leetcode-1i2h</guid>
      <description>&lt;p&gt;When I started learning software development last year, I heard the word "LeetCode" mentioned before but I never took it upon myself to look into it until now, as a more seasoned developer. &lt;/p&gt;

&lt;p&gt;LeetCode is a platform and community centered around assessing technical proficiency and preparing for interviews for tech companies. The platform consists of over 2000 code problems ranging in difficulty and a multitude of discussions across the community. Founded in 2015, and becoming international in 2018, LeetCode has built a large community and impact in the industry.&lt;/p&gt;

&lt;p&gt;With so many problems across the spectrum of difficulty, LeetCode provides coding assessments and exercises for beginners and advanced developers around the world. According to &lt;a href="https://www.linkedin.com/pulse/leetcode-jovitha-sukunthan-kkrcc/"&gt;Jovitha Sukunthan&lt;/a&gt;, LeetCode supports Java, C, JavaScript, Ruby, Python, C++, and PHP to name a few. These problems cover algorithms, data structures, dynamic programming, SQL, AI, and databases. In addition to providing problems, the community provides solutions!&lt;/p&gt;

&lt;p&gt;As developers, we know there are many ways to arrive at a solution when facing a problem while coding or implementing a new concept. In the discussion sector of LeetCode, solutions are shared for problems, allowing developers to compare the steps they took to get the same solution and explain their reasoning. With these discussions available, one can find a new skill to add to their toolbelt. &lt;a href="https://duncan-mcardle.medium.com/what-is-leetcode-and-why-do-i-post-solutions-to-it-on-medium-d40fb958bbc2"&gt;Duncan McArdle&lt;/a&gt; shares that he was able to learn about Hash Maps from LeetCode discussions for a problem he solved and now knows to consider them as an option for drafting up solutions. That being said, posting your solution with your explanation can have a similar impact on developers like you in the future.&lt;/p&gt;

&lt;p&gt;Another aspect of LeetCode is its use in the hiring process in the tech industry. Lots of large tech companies, including FAANG (Facebook, Amazon, Apple, Netflix, and Google), use problems from LeetCode in the hiring process. With a premium account, you can have access to some of the problems that might come up in the interview as well as the solutions people have provided. This allows Leetcode to be a good tool for interview preparation but producing a solution will not guarantee the position you are interviewing for. Part of the process focuses on your ability to &lt;a href="https://duncan-mcardle.medium.com/what-is-leetcode-and-why-do-i-post-solutions-to-it-on-medium-d40fb958bbc2"&gt;"identify methods and apply concepts"&lt;/a&gt; instead of the actual answer you submit. With that being said, it might be better to reference the answers for recognizing patterns that might fare better with certain details of problems, than trying to remember the code someone posted.&lt;/p&gt;

&lt;p&gt;Another way Leetcode can be used as an interview prep tool is that it provides mock interviews and mock code assessments. LeetCode can simulate real code assessments from companies like Google, Uber, Microsoft, and Adobe, with a premium membership of course. However, they do have options for their regular members that simulate different types of interviews. &lt;/p&gt;

&lt;p&gt;In my research of learning about LeetCode, I wanted to know what companies were known for using LeetCode in their hiring process and there were more results for companies that do not use LeetCode and some admitting their displeasure for LeetCode altogether. Some of the posts described LeetCode as unorganized and alleged it was centered around memory-based learning. From what I saw in my research, I didn't see anything claiming that LeetCode would be an educating tool, but more so that it has resources available to introduce you to concepts that will push you to learn them. As far as the website being unorganized, in my brief time using it, I can only attest to the interface for the Problems section being "unorganized" because there doesn't seem to be any rhyme or reason with the display. However, I think this is something that could be overlooked by many. Another comment was directed at the limited access without a premium membership, I can also agree that the gap makes a difference in its effectiveness but this could vary based on the user's purpose for using LeetCode.&lt;/p&gt;

&lt;p&gt;With so many opinions about LeetCode, I decided to try it out myself and see what it's like to solve a problem of theirs. The problem I chose was &lt;a href="https://leetcode.com/problems/return-length-of-arguments-passed/"&gt;#2703 "Return Length of Arguments Passed"&lt;/a&gt; just to get a feel for the website and its features. It was an easy problem under the Javascript tag, where you are responsible for returning the number of arguments passed to the function. When you have the problem open, the solutions are available to you to look at as well as comments/discussions from members of the community. Upon submission, a graph shows where you fall in their range of runtime for submitted solutions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwxg36job78pd1bm1yptw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwxg36job78pd1bm1yptw.png" alt="Image description" width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Overall, I can see LeetCode can be useful to developers at any stage of their career. Despite its shortcomings, I believe that LeetCode can sharpen your technical skills as well as your interview skills. Having a community makes a world of a difference when trying something new, especially as adult learners who are heading in similar directions and I see the LeetCode community easing the growing pains of increasing your skills. If you are teaching yourself how to code, the Problems can be especially helpful in gauging your understanding of concepts. In summation, I think everyone who is breaking into tech and software development could benefit from using LeetCode in some way, shape, or form; whether it be for testing your proficiency, preparing for an interview, or connecting with other developers.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>leetcode</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What is AngularJS?</title>
      <dc:creator>allyn</dc:creator>
      <pubDate>Mon, 08 Apr 2024 03:44:41 +0000</pubDate>
      <link>https://dev.to/allyn/what-is-angularjs-5fi4</link>
      <guid>https://dev.to/allyn/what-is-angularjs-5fi4</guid>
      <description>&lt;p&gt;As I dip my toe in JavaScript frameworks in my learning journey, I come across AngularJS. I had a very brief and unsuccessful run-in with AngularJS and with that failure, I decided to look into what AngularJS was to demystify it and get more comfortable with it. Since my journey of learning Javascript includes learning the many tools of the language, mainly jQuery, I will also be comparing the 2. &lt;/p&gt;

&lt;p&gt;Before I get too deep in the weeds of this post, I'd like to insert distinctions between libraries and frameworks. Libraries provide functions that can be used when the developer feels the need to. Frameworks are implementations that have your code used for the details of said implementation. As part of learning the tools of JavaScript, I have come to learn the difference between libraries (jQuery) and frameworks (AngularJS).&lt;/p&gt;

&lt;p&gt;AngularJS is a framework that is used to create dynamic web applications. It allows the developer to use an HTML template and &lt;a href="https://docs.angularjs.org/guide/introduction"&gt;"extend its syntax"&lt;/a&gt; to display the components of the app. More specifically, AngularJS allows the developer to create cleaner and reusable code for CRUD apps with features such as data binding, modules, and giving DOM elements specific behavior through the templates.&lt;/p&gt;

&lt;p&gt;By adding AngularJS to your application, you will first have to create a module, which is essentially a container for your controllers and directives. You can have multiple angular modules in your application tailored to handle specific features or hold certain directives. When you load up your app, the modules inserted will pause the execution of the application to &lt;a href="https://docs.angularjs.org/guide/module"&gt;"resolve"&lt;/a&gt; dependencies. To create your module, you will call on the module with the module method, pass in a string of the name of your method, and an array that would point to any modules that the module you are creating depends on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;angular.module('myApp', []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I mentioned before, modules can contain controllers which can be defined as &lt;a href="https://docs.angularjs.org/guide/controller"&gt;"a JavaScript constructor function that is used to augment the AngularJS Scope"&lt;/a&gt;. The controller will define a new scope just like JavaScript functions normally do and with that scope, you can add behavior. This scope's syntax is &lt;code&gt;$scope&lt;/code&gt; and is an object, a tangible function "scope" that you can add to. To create a controller, you call the controller method on the module created, pass in the string of the name of the controller, and an array of the initial state of the $scope object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MyApp.controller('theController, [$scope, function(){}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add behavior to DOM elements, you have to add what is called directives to the DOM element that you want to adopt the behavior specified. These directives are inserted similarly to an HTML attribute and have a "ng" prefix.&lt;br&gt;
&lt;code&gt;&amp;lt;div ng-bind="context"&amp;gt;&lt;/code&gt;&lt;br&gt;
AngularJS comes with some built-in directives but you also can create your own. To create your own directive, you'll first have to have a module to attach it to. Applications can have many modules that handle various features. The general syntax of creating a directive is to give the directive a name and a callback function that describes the behavior.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;angular.module('moduleName', [])
  .directive('directiveName', function() {
    // insert behavior
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The AngularJS documentation describes data binding as the "automatic synchronization of data between the model and view components," meaning when one component changes, these changes are updated across the board. The use of double curly braces &lt;code&gt;{{}}&lt;/code&gt; is indicative of data binding in AngularJS that displays content from the model to the view. This can be used in place of the &lt;code&gt;ng-bind&lt;/code&gt; directive.&lt;/p&gt;

&lt;p&gt;Data binding and directive take away from the initialization process of JavaScript which makes for cleaner more succinct code. Instead of creating variables that point to various locations of the DOM and initializing dynamic functions that can be used in multiple locations of the web app, you can create the directive that contains the reusable function and insert the directive in the DOM element. Think of when only using JS and jQuery to create a dynamic web app, creating variables that point to DOM elements and writing functions that have sprinkled in jQuery. This can become redundant if you have components with similar needs.&lt;/p&gt;

&lt;p&gt;One of the (personal) drawbacks of AngularJS is what comes with learning new frameworks and that is adjusting to the syntax/implementation of the framework. Personally, there is a learning curve with conforming to AngularJS. Another would be that AngularJS is not suitable for every web application. Since AngularJS simplifies the creation of CRUD applications, this means that if your application does not include CRUD programming such as games or business-based applications, AngularJS would not be needed. Also with the increase of abstraction, that means that your code becomes less flexible. As mentioned before, data binding synchronizes the model and view so when one changes, so does the other. This can become worrisome for beginner developers as a separation of concerns is removed.&lt;/p&gt;

&lt;p&gt;AngularJS and jQuery share DOM manipulation to an extent so it may be difficult to discern when to use the 2. Since one is a framework and the other is a library, one might opt to use both but their closeness in front-end usage makes it difficult as well as unnecessary to use both. In a post by &lt;a href="https://www.linkedin.com/pulse/angularjs-jquery-which-one-should-you-use-your-next-project/"&gt;SynapseIndia&lt;/a&gt;, AngularJS would be the better option for large applications with a simple layout but complex structure whereas jQuery can be used for more overall simpler and smaller applications&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>angular</category>
    </item>
    <item>
      <title>Dive into ES6 pt. 2</title>
      <dc:creator>allyn</dc:creator>
      <pubDate>Mon, 26 Feb 2024 12:55:41 +0000</pubDate>
      <link>https://dev.to/allyn/dive-into-es6-pt-2-nem</link>
      <guid>https://dev.to/allyn/dive-into-es6-pt-2-nem</guid>
      <description>&lt;p&gt;In this post, we'll go over, generators, iterators, proxies, and reflections.&lt;/p&gt;

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

&lt;p&gt;Generators can be broken down conceptually into 2 parts; the function and the object. But as a whole, they are functions that can return multiple values sequentially. Let's take a look at the syntax first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function* greeting () {
  yield 'Hello!';
  yield 'Good morning!';
  return 'Have a nice day!';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason why generators can be broken down into 2 parts is because when you make your function call, the code does not execute. Instead, it returns an object, known as the generator object, to handle execution. This object consists of 2 values; the &lt;code&gt;value&lt;/code&gt; property which holds on to the returned value, and &lt;code&gt;done&lt;/code&gt; which represents the completion status of the function with a boolean.&lt;/p&gt;

&lt;p&gt;Let's dive a little deeper.&lt;/p&gt;

&lt;p&gt;Since the call to the generator returns the generator object, how will we begin to execute the code? With the &lt;code&gt;next()&lt;/code&gt; method! When you invoke the &lt;code&gt;next()&lt;/code&gt; method, it runs the execution until it hits the first yield statement. Once we hit our yield, the function pauses and returns whatever value follows &lt;code&gt;yield&lt;/code&gt;. In the example above the first call to &lt;code&gt;greeting().next()&lt;/code&gt; will return "Hello!" and wait for the next call to &lt;code&gt;greeting().next()&lt;/code&gt; to continue. This also updates our generator object. After the first call to &lt;code&gt;greeting().next()&lt;/code&gt;, our generator object now looks like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ value: 'Hello!', done: false }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;value&lt;/code&gt; property has its value from our yield statement and &lt;code&gt;done&lt;/code&gt; has a value of false because our function isn't complete. Once our function hits the return statement, the done value will become true. Continuous calls to the next method will progress our function. &lt;/p&gt;

&lt;p&gt;A feature of generators is generator composition which allows you to &lt;a href="https://javascript.info/generators#generator-composition"&gt;'transparently "embed" generators in each other'&lt;/a&gt;. By using the &lt;code&gt;yield*&lt;/code&gt; syntax, we're able to &lt;em&gt;compose&lt;/em&gt; inner generators inside an outer generator. This also does not compromise memory to store the results.&lt;/p&gt;

&lt;p&gt;Yield can not only return values, it can also receive them. You can pass arguments into the &lt;code&gt;next&lt;/code&gt; method which will take the place of the yield statement.&lt;/p&gt;

&lt;p&gt;Moving on to iterators.&lt;/p&gt;

&lt;p&gt;According to MDN, an iterator can be defined as an object containing a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#iterators"&gt;"&lt;code&gt;next()&lt;/code&gt; method that returns an object with two properties."&lt;/a&gt; This would make generators an iterator.&lt;/p&gt;

&lt;p&gt;On to Proxies.&lt;/p&gt;

&lt;p&gt;In plain English, proxies are something used to represent the value of another thing. In programming, proxies are objects used in place of another object. With proxies, you also can redefine essential object operations including getting and setting.&lt;/p&gt;

&lt;p&gt;Proxies are created with 2 parameters: the &lt;code&gt;target&lt;/code&gt; which is your focal object, and the &lt;code&gt;handler&lt;/code&gt; which is an object of the operations you are redefining. The proxy object also acts as a prototype chain, meaning you can access properties from your target object and perform lookups.&lt;/p&gt;

&lt;p&gt;Handlers are sometimes referred to as traps because they can "trap" certain operations. Let's take a look at this example from MDN.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const target = {
  message1: "hello",
  message2: "everyone",
};

const handler2 = {
  get(target, prop, receiver) {
    return "world";
  },
};

const proxy2 = new Proxy(target, handler2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we try to access our target properties, what do you think will happen? If you have peered into data structures, specifically hash tables, you remember that JS objects are instances of hash tables, which means they come with getting and setting operations. Instead of calling get or set methods on objects, we use dot or bracket notation. So if we were to try to access our target object's properties, we would get 'world' back instead of the properties because we overwrote our get operation. This is a trap.&lt;/p&gt;

&lt;p&gt;Finally, let's peak into Reflections.&lt;/p&gt;

&lt;p&gt;Reflections are often used in conjunction with proxies because the Reflect object simplifies creating proxies. The Reflect object consists of static methods and cannot be constructed, like the Math object. These methods are named just like the methods one would redefine in a proxy. Reflections can save you from traps like our &lt;code&gt;get&lt;/code&gt; method by allowing us to use default operations.&lt;/p&gt;

&lt;p&gt;This concludes my dive into ES6. Happy coding!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Dive into ES6</title>
      <dc:creator>allyn</dc:creator>
      <pubDate>Thu, 22 Feb 2024 06:51:26 +0000</pubDate>
      <link>https://dev.to/allyn/dive-into-es6-3ag</link>
      <guid>https://dev.to/allyn/dive-into-es6-3ag</guid>
      <description>&lt;p&gt;I began learning JavaScript using the ES5 version to understand the fundamentals of the language. Once I got my feet wet with ES5, I was introduced to ES6. There were so many updates that I became too anxious to fully immerse myself into another level of JavaScript until recently. This will be part 1 of my learning journey of ES6. In this post, we’ll review Promises, destructuring, Modules, transpiling, and the spread and rest operators.&lt;/p&gt;

&lt;p&gt;Starting with Modules.&lt;/p&gt;

&lt;p&gt;Modules are collections of small independent units known as components. Components can be described as “everything that can be exported by the &lt;code&gt;export&lt;/code&gt; statement that can be reused in our application” by Dler Ari in &lt;a href="https://www.freecodecamp.org/news/how-to-use-es6-modules-and-why-theyre-important-a9b20b480773/"&gt;A Practical Guide to ES6 modules&lt;/a&gt;. These modules improve scalability which is the ability to adapt to large amounts of data without compromising performance and efficiency. By “encapsulating behavior”, debugging becomes easier to pinpoint. Modules allow a separation of concerns and give you the ability to import and export only the necessary modules for your functionality which keeps your code DRY (Don’t Repeat Yourself).&lt;/p&gt;

&lt;p&gt;Next: Spread and Rest Operators.&lt;/p&gt;

&lt;p&gt;Differentiating the two operators can be difficult considering they have identical syntax: &lt;code&gt;...value&lt;/code&gt;. The difference can be seen by examining the logic using the operator. Despite looking the same, the spread operator and rest operator are opposites of each other. The spread operator expands iterable values into a collection and the rest operator condenses the remaining values into a collection. On top of that, you can do a multitude of things with the spread operator; you can split strings into an array, copy values from collections into other collections, and pass function arguments. For the rest operator, you can reduce values into a condensed collection.&lt;/p&gt;

&lt;p&gt;Moving on to destructuring.&lt;/p&gt;

&lt;p&gt;To destructure is to extract values from arrays, and properties from objects, and store them in a variable. There are many uses for destructuring, such as swapping values or used as function parameters, but the main object of destructuring is accessing certain values in collections. Let’s start with the syntax for destructuring&lt;/p&gt;

&lt;p&gt;At first glance, it appears to be the inverse operation for variable assignment which is close to what destructuring does behind the scenes. Depending on the collection you are destructuring, your variables will directly correspond with the collection’s values. If you are extracting from an array, the order of the variables will affect what element will be assigned to it; the first variable will be the value at the 0th index, the second variable will point to the 1st index, etc. When extracting from an object, the variable name will have to match the property’s key that you are targeting. Thankfully there’s a workaround for each of these issues.&lt;/p&gt;

&lt;p&gt;The comma separator allows you to skip elements when destructing arrays. Keep the space empty between the commas to determine the element you want to skip over.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const campers = ['Lazlo', 'Clam', 'Raj', 'Lumpus']

const [duckDuck,,, goose] = campers;
console.log(goose); // Lumpus
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you wanted to assign a new variable to an object’s property but didn’t want it to have the same name as the property’s key, you could do just that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myCar = {
  color: 'red',
  year: 2004,
  hasGas: false
}

const { color : jetta } = myCar;
console.log(jetta); // red
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also incorporate the rest operator in destructuring to stash leftover values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const family = {
  daughter: 'Peppa',
  mother: 'Mummy Pig',
  father: 'Daddy Pig'
};

const { daughter, ...parents} = family;
console.log(parents); // {mother: 'Mummy Pig', father: 'Daddy Pig'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s look at transpiling.&lt;/p&gt;

&lt;p&gt;Aakarshit Giri said in his &lt;a href="https://www.linkedin.com/pulse/javascript-transpiler-aakarshit-giri/"&gt;JavaScript Transpiler&lt;/a&gt; article, transpilers (aka transformation compilers) “convert code written in one programming language into another programming language while preserving the original functionality”. In other words, taking out ES6 code + converting it into ES6 so it can be read by all browsers/networks. Popular transpilers include Babel and Webpack. In this post, we’ll focus on Babel.&lt;/p&gt;

&lt;p&gt;Babel transpiles versions of Javascript, mainly from ES6 into “backward compatible” versions suitable for browsers/environments. Made from plugins, Babel targets certain syntax and refactors the code to fit the desired version. For example, the &lt;a href="https://babeljs.io/docs/usage#plugins--presets"&gt;&lt;code&gt;@babel/plugin-transform-arrow-functions&lt;/code&gt;&lt;/a&gt; plugin targets arrow functions and transforms them into function expressions/definitions with the &lt;code&gt;function&lt;/code&gt; keyword and maintains functionality. With that being said, you run the risk of having larger, less efficient code. However, that does not hinder your ability to write cleaner code.&lt;/p&gt;

&lt;p&gt;And finally, we’re on to Promises.&lt;/p&gt;

&lt;p&gt;MDN defines promises as an object that represents the eventual completion or failure of an asynchronous operation and its resulting value. GeeksforGeeks likens promises to a receipt being that the receipt is a promise that you will receive your order and is a placeholder for your purchase. These promises came about as a means to avoid callback hell, which is excessive nesting of callback functions that increases the complexity of the code you’re writing and also makes it difficult to read and execute. Promises have a task that will be checked for success or failure and instructions on what to do depending on the execution of the task.&lt;/p&gt;

&lt;p&gt;From reading that, one would infer that the instructions for the result of the operation would be callback functions and they are! Except they aren’t passed into functions, instead they are attached to the promise, like methods (which is what they are).&lt;/p&gt;

&lt;p&gt;The callbacks you’ll chain to promises will either be &lt;code&gt;.then()&lt;/code&gt; or &lt;code&gt;.catch()&lt;/code&gt;. The &lt;code&gt;then&lt;/code&gt; method handles both success and error callbacks and &lt;code&gt;catch&lt;/code&gt; is used for error handling. You can use the &lt;code&gt;then&lt;/code&gt; method for only telling the program what to do if the operation is completed because the second parameter is reserved for an optional error callback. But if all of your error handling for every step in the chain is the same, you can use &lt;code&gt;catch&lt;/code&gt; at the end of the chain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myPromise = new Promise((resolve, reject) =&amp;gt; {
  let a = false;
  setTimeout(() =&amp;gt; {
    return (a) ? resolve('a is found!'): reject('sorry, no a');
  }, 300);
}); 

myPromise
.then(value =&amp;gt; { console.log(value) })
.catch(err =&amp;gt; { console.log(err) });

// 'sorry, no a'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example from Kingsley Ubah in his &lt;a href="https://www.freecodecamp.org/news/what-is-promise-in-javascript-for-beginners/"&gt;post&lt;/a&gt; about Promises, he provides a great example of what a promise chain looks like and its behavior. The code shows what the outcomes will be once the Promise is &lt;a href="https://www.geeksforgeeks.org/es6-promises/"&gt;settled&lt;/a&gt;. Since &lt;code&gt;myPromise&lt;/code&gt; rejects or fails, we know that the error will be logged to the console. A question that may come to mind is 'how do we reach the catch method?' and the answer to that is the &lt;code&gt;then&lt;/code&gt; method will return a Promise regardless of its completion or failure. If we do not return a Promise, we won't be able to determine its status of completion, and that will lead to a multitude of errors.&lt;/p&gt;

&lt;p&gt;These new features make accessing values more flexible, code more readable, and averts errors. This concludes part one of my deep dive into ES6 features. In my next post, I will go over generators, iterators, proxies, and reflections.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>es6</category>
      <category>programming</category>
    </item>
    <item>
      <title>Ruby on Rails vs. JavaScript</title>
      <dc:creator>allyn</dc:creator>
      <pubDate>Mon, 05 Feb 2024 14:16:31 +0000</pubDate>
      <link>https://dev.to/allyn/ruby-on-rails-vs-javascript-1i12</link>
      <guid>https://dev.to/allyn/ruby-on-rails-vs-javascript-1i12</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;As a beginner to software development, I want to explore the many different programming languages available. Today we’ll be taking a look at one of the most popular beginner friendly programming languages, Ruby on Rails. We’ll be looking at what RoR is, what it’s used for, it’s architecture, and how it compares to my main programming language, JavaScript.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Ruby on Rails?
&lt;/h3&gt;

&lt;p&gt;In &lt;a href="https://www.codingdojo.com/blog/what-is-ruby-on-rails#:~:text=Ruby%20on%20Rails%20(RoR)%20is,websites%2C%20apps%2C%20and%20systems."&gt;“What Is Ruby on Rails, And What Is It Used For?”&lt;/a&gt; Brad Mitchell describes RoR as ‘open-source full-stack framework software specifically to build different web applications.’ Ruby on Rails can be broken up into 2 parts: Ruby and Rails. Ruby is the all-around programming language and Rails is the framework that is utilized for web development and app creation. Ruby is a primarily back-end language but works with HTML, CSS, and JS for the front-end. This is due to the architecture of Ruby on Rails. One of the main reasons RoR is so popular is because a lot of the work is done for you and is simplified for the programmer. Ruby also have 2 philosophies to follow: DRY (“Don’t Repeat Yourself) and “convention over configuration” or CoC. CoC is to make programming easier as long as you follow the conventions of the language. &lt;/p&gt;

&lt;h3&gt;
  
  
  Ruby on Rails Architecture
&lt;/h3&gt;

&lt;p&gt;Ruby on Rails follows the Model-View-Controller pattern. The model component interacts with the database and manages the data that will then be passed to the view component. Guessing from the name, this component pertains to anything that will be visible to the user. With the view component falling on the front end, we will incorporate HTML, CSS, and even Javascript into our code to make a dynamic and presentable website or application. Lastly is our controller component that ties everything together. The controller component “receives data from the model component and passes it to the view component” as said in &lt;a href="https://intellipaat.com/blog/what-is-ruby-on-rails/#:~:text=types%20of%20content.-,Ruby%20on%20Rails%20Architecture,and%20maintain%20complex%20web%20applications."&gt;‘What is Ruby on Rails?’&lt;/a&gt; by Ashish Thakur.&lt;/p&gt;

&lt;p&gt;Let’s take a look at an example of a model in Ruby.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# == Schema Information
#
# Table name: users
#
#  id                  :integer          not null, primary key
#  aspiring_occupation :string
#  bio                 :string
#  display_name        :string
#  email               :string
#  employer            :string
#  occupation          :string
#  password_digest     :string
#  created_at          :datetime         not null
#  updated_at          :datetime         not null
#
class User &amp;lt; ApplicationRecord
  validates :email, :uniqueness =&amp;gt; { :case_sensitive =&amp;gt; false }
  validates :email, :presence =&amp;gt; true
  has_secure_password

  has_many(:ai_messages, { :class_name =&amp;gt; "AiMessage", :foreign_key =&amp;gt; "user_id", :dependent =&amp;gt; :destroy })

  def prompt
    &amp;lt;&amp;lt;~TEXT

    TEXT
  end

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

&lt;/div&gt;



&lt;p&gt;In the above image, we can see how simple it is to interact with the database. When I said that a lot of the work is done for me, this is a glimpse into that. I did not type most of that file. Majority is what was generated for me when I passed the data model code as a command in the terminal. When creating a User model, Ruby on Rails knows that we will need to verify the user's information so each User model will automatically know to verify the user when signing in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="my-3"&amp;gt;
  &amp;lt;div&amp;gt;
    &amp;lt;h1 class="sr-only"&amp;gt;
      Message details
    &amp;lt;/h1&amp;gt;

    &amp;lt;div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;a href="/ai_messages"&amp;gt;
          Go back
        &amp;lt;/a&amp;gt;
      &amp;lt;/div&amp;gt;


    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;hr&amp;gt;

&amp;lt;div class="card" &amp;gt;
  &amp;lt;ul class="list-group"&amp;gt;
    &amp;lt;li class="list-group-item"&amp;gt;&amp;lt;%= @user_message.content %&amp;gt;&amp;lt;/li&amp;gt;
    &amp;lt;li class="list-group-item"&amp;gt;&amp;lt;%= @assistant_message.content %&amp;gt;&amp;lt;/li&amp;gt;
  &amp;lt;/ul&amp;gt;
  &amp;lt;div class="card-footer"&amp;gt;
    &amp;lt;%= time_ago_in_words(@user_message.created_at) %&amp;gt; ago
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;hr&amp;gt;

&amp;lt;div class="my-3"&amp;gt;
  &amp;lt;a href="/delete_ai_message/&amp;lt;%= @user_message.id %&amp;gt;"&amp;gt;
    Delete Message
  &amp;lt;/a&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here in the view component, we have mainly HTML but instead of using script tags to have our backend interact with the front like we do in JS, we have embedded ruby tags that specify where exactly we want these pieces of memory to interact.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def create
    @user = User.new
    @user.email = params.fetch("query_email")
    @user.password = params.fetch("query_password")
    @user.password_confirmation = params.fetch("query_password_confirmation")
    @user.occupation = params.fetch("query_occupation")
    @user.bio = params.fetch("query_bio")
    @user.display_name = params.fetch("query_display_name")
    @user.employer = params.fetch("query_employer")
    @user.aspiring_occupation = params.fetch("query_aspiring_occupation")

    save_status = @user.save

    if save_status == true
      session[:user_id] = @user.id

      redirect_to("/ai_messages", { :notice =&amp;gt; "User account created successfully."})
    else
      redirect_to("/user_sign_up", { :alert =&amp;gt; @user.errors.full_messages.to_sentence })
    end
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this controller component we can see how the model and view components intermingle. Certain aspects of our controller manage data from our model and direct to the view (look for the word ‘template’ followed by an arrow pointing to a html.erb file which is an HTML page with embedded ruby).&lt;/p&gt;

&lt;h3&gt;
  
  
  What is RoR used for?
&lt;/h3&gt;

&lt;p&gt;Ruby on Rails can be used for making a multitude of programs, such as social network apps, content-management systems, and project management tools. Ruby has produce such versatile results with the help of RubyGems. Morganne Gagne describes Ruby gems as “open source libraries that contain Ruby code and are packaged with a little extra data” in her blog &lt;a href="https://medium.com/@morgannegagne/what-is-a-ruby-gem-1eec2684e68"&gt;‘What is a Ruby Gem?’&lt;/a&gt;. These can be compared to libraries like Moment.js, Underscore.js, or jQuery.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ruby on Rails vs JavaScript
&lt;/h3&gt;

&lt;p&gt;One of the biggest benefits of Ruby is how clear it is to read. Ruby is known for how easy it is to read and it’s built in framework that makes it easier for beginners to create web applications, but how does it compare to JavaScript?&lt;/p&gt;

&lt;p&gt;RubyGems allow a lot of work to be simplified but one of the downsides of the gems is that some conflicts can arise. With an over reliance of Ruby gems, your gems can become incompatible. Gems are created by developers in the Ruby community so conflicts are a possibility. On the other hand, JavaScript libraries don’t have the issue of affecting the performance of another. &lt;/p&gt;

&lt;p&gt;A huge difference between Ruby and Javascript is that Ruby is a compiled language while JavaScript is an interpreted language. Compiled languages translates the program into machine readable code. This can result in your program taking up a lot of memory. Interpreted languages produce a result from running the code, this means that you can run JS in your browser and see real time changes.&lt;/p&gt;

&lt;p&gt;While Ruby on Rails is one of the most-popular amongst newbies, JavaScript is one of the most used programming languages across the world with “98.4% of websites using JavaScript”, stated by &lt;a href="https://www.semrush.com/blog/javascript/"&gt;Zach Paruch&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;Ruby on Rails is a great introduction to coding with clear syntax, simplified code conventions, an expansive library and interactive framework to show you the wonders of web development. In fact, Ruby on Rails was the first programming language I learned and the code examples you see are from my first application that I created only 3 months into coding. Ruby on Rails being my first language made programming less scary and learning JavaScript easier due to their similarities. I say all this to say that Ruby on Rails are not competitors but more like teammates and they have their own specific benefits that make them great for learning.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ruby</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Higher Order Functions from a Big Brain</title>
      <dc:creator>allyn</dc:creator>
      <pubDate>Tue, 09 Jan 2024 01:00:45 +0000</pubDate>
      <link>https://dev.to/allyn/higher-order-functions-from-a-big-brain-433</link>
      <guid>https://dev.to/allyn/higher-order-functions-from-a-big-brain-433</guid>
      <description>&lt;p&gt;Higher order functions(HOFs) are a great way to simplify code when working with arrays. They iterate through the passed array for you and invoke the passed callback function to each iteration of the array. In addition, their return value varies depending on the HOF. You can slice the lines of code you have to write in half, making it more efficient for you.&lt;/p&gt;

&lt;p&gt;The main idea with HOFs is that they do a lot of the work for you. The most you have to do is come up with the callback function that will be called on each element of the array. Since you will have an idea of what the contents of the array will be, writing the code becomes simpler because your parameter(s) be used to indicated the type of element(s) you will deal with. And with some of them, you can return a value that is not an array, such as an object, string, or number which can be even less code to write.&lt;/p&gt;

&lt;p&gt;Starting off with the &lt;code&gt;.forEach()&lt;/code&gt; method.&lt;/p&gt;

&lt;h2&gt;
  
  
  .forEach()
&lt;/h2&gt;

&lt;p&gt;To help you visualize how &lt;code&gt;.forEach()&lt;/code&gt; works, I'll give you an example of how it could be written.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;forEach = (array, callback) =&amp;gt; {
  for (let i = 0; i &amp;lt; array.length; i++){
    callback(array[i]);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method applies the callback method to each element of the array it is called on and is one of the functions that can return any data type, hence the lack of a return statement in the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = ['Allyn', 'Nancy', 'Kelly'];

let forEachExample = arr.forEach((person) =&amp;gt; {
  console.log(`Hello ${person}!`)
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of this code does not return an array but instead, logs each element inside the &lt;code&gt;arr&lt;/code&gt; array to the console.&lt;/p&gt;

&lt;p&gt;Next is the .map() method.&lt;/p&gt;

&lt;h2&gt;
  
  
  .map()
&lt;/h2&gt;

&lt;p&gt;The .map() method is very similar to &lt;code&gt;.forEach()&lt;/code&gt; except it returns a new array that consists of the results from invoking the callback method on each element. Let's take a closer look.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;map = (array, callback) =&amp;gt; {
  var output = [];
  for (let i = 0; i &amp;lt; array.length; i++){
    output.push(callback(array[i]));
  }
  return output;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At a glance, &lt;code&gt;.forEach()&lt;/code&gt; and &lt;code&gt;.map()&lt;/code&gt; appear nearly identical but the difference is that &lt;code&gt;.map()&lt;/code&gt; returns &lt;code&gt;output&lt;/code&gt;, an array of the modified elements.&lt;/p&gt;

&lt;p&gt;In this example, we'll use an array consisting of objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cities = [
  {
    city: 'New Orleans',
    state: 'Louisiana',
  }, 
  {
    city: 'Chicago',
    state: 'Illinois',
  }, 
  {
    city: 'Los Angeles',
    state: 'California',
  }, 
  {
    city: 'Houston',
    state: 'Texas',
  }
];

let mappedCities = cities.map((place) =&amp;gt; {
  return `${place.city}, ${place.state}`;
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;.map()&lt;/code&gt; acts on each element of the &lt;code&gt;cities&lt;/code&gt; array and calls the callback function on each element and returns a new array with the modified elements from &lt;code&gt;cities&lt;/code&gt;. If you were to log &lt;code&gt;mappedCities&lt;/code&gt;, you would see that the &lt;code&gt;cities&lt;/code&gt; array now consists of strings in place of the objects and formats the cities in a human-friendly way.&lt;/p&gt;

&lt;p&gt;Up next: .filter()&lt;/p&gt;

&lt;h2&gt;
  
  
  .filter()
&lt;/h2&gt;

&lt;p&gt;Similarly to &lt;code&gt;.map()&lt;/code&gt;, &lt;code&gt;.filter()&lt;/code&gt; returns an array that contains the return values from the callback function. Except that these values are not modified and they are only returned if their result after invoking the callback function is true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;filter = (array, callback) =&amp;gt; {
  var output = [];
  for (let i = 0; i &amp;lt; array.length; i++){
    if (callback(array[i])){
      output.push(array[i]);
    }
  }
  return output;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's look at an example of how &lt;code&gt;.filter()&lt;/code&gt; works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const students = [
  {
    firstName: 'Sydney',
    grade: 88,
  }, 
  {
    firstName: 'Steve',
    grade: 74,
  }, 
  {
    firstName: 'Matthew',
    grade: 78,
  }, 
  {
    firstName: 'Chris',
    grade: 65,
  }, 
  {
    firstName: 'Patrick',
    grade: 70,
  }, 
  {
    firstName: 'Tyler',
    grade: 99,
  }
];

let over75 = students.filter((student) =&amp;gt; student.grade &amp;gt; 75);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we log &lt;code&gt;over75&lt;/code&gt; to the console, we see that the array is shorter than the &lt;code&gt;students&lt;/code&gt; array. That's because &lt;code&gt;over75&lt;/code&gt; only consists of students whose grade was over 75.&lt;/p&gt;

&lt;p&gt;On to the more complex HOF: .reduce&lt;/p&gt;

&lt;h2&gt;
  
  
  .reduce()
&lt;/h2&gt;

&lt;p&gt;What sets .reduce() apart from the rest of these HOFs are the parameters. It takes in a callback function like the rest but there is an additional optional parameter, known as the seed or initial value, that determines what the return value will be and is the starting value of the function. However it can get a little more complicated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;reduce = (array, callback, seed) =&amp;gt; {
  let output;
  if (seed === undefined) {
    output = array[0]
    for (let i = 1; i &amp;lt; array.length; i++){
      output = callback(seed, array[1]);
    }
  } else {
    for (let x = 0; x &amp;lt; array.length; x++) {
      output = callback(output, array[i]);
    }
  }
  return output;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The callback functions parameters can be referred to as the accumulator and the current value at call time. If an initial value parameter is provided, when the callback function is invoked, the accumulator holds on to the initial value and will determine the return value. If the initial value is not provided, the accumulator will point to the first item of the array. This leads to what the current value parameter will be. The current value parameter will point to the first value of the array if an initial value is not passed, if it is, the current value will point to the next element in the array.&lt;/p&gt;

&lt;p&gt;The object of this function is to "reduce" the array into a single value.&lt;/p&gt;

&lt;p&gt;Let's look at an example of calling &lt;code&gt;.reduce()&lt;/code&gt; on an array without passing a seed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let nums = [5, 10, 15, 20];

let sum = nums.reduce((acc, curr) =&amp;gt; acc + curr);
console.log(sum);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of this code is the 50 which is the sum of all the elements of the array, meaning &lt;code&gt;nums&lt;/code&gt; has been reduced to 1 number. Without having a seed value, &lt;code&gt;.reduce()&lt;/code&gt; started at the first element, &lt;code&gt;5&lt;/code&gt;, which is why the return value is a number.&lt;/p&gt;

&lt;p&gt;Now let's look at an example of calling &lt;code&gt;.reduce()&lt;/code&gt; but with a seed value this time. For this example, we'll be using the &lt;code&gt;students&lt;/code&gt; array from the &lt;code&gt;.map()&lt;/code&gt; example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const students = [
  {
    firstName: 'Sydney',
    grade: 88,
  }, 
  {
    firstName: 'Steve',
    grade: 74,
  }, 
  {
    firstName: 'Matthew',
    grade: 78,
  }, 
  {
    firstName: 'Chris',
    grade: 65,
  }, 
  {
    firstName: 'Patrick',
    grade: 70,
  }, 
  {
    firstName: 'Tyler',
    grade: 99,
  }
];

let studentGrades = students.reduce((acc, curr) =&amp;gt; {
  acc.push(curr.grade);
  return acc;
}, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you log &lt;code&gt;studentGrades&lt;/code&gt; to the console, you see that instead of there being an array of objects, it's an array of just the grades from all the students.&lt;/p&gt;

&lt;p&gt;From what we've seen in these examples, HOFs do a lot of the coding for you, leaving you to attach your HOF of choice to an array and only giving it specific directions as a function to do the work for you. In summation, HOFs can be used for sorting, modifying, filtering, and accumulating and make your code more flexible. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
