<?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: JustinBass</title>
    <description>The latest articles on DEV Community by JustinBass (@justinbass).</description>
    <link>https://dev.to/justinbass</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%2F970913%2F07e8bb7a-636b-485a-8aed-9a596ab2652c.jpeg</url>
      <title>DEV Community: JustinBass</title>
      <link>https://dev.to/justinbass</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/justinbass"/>
    <language>en</language>
    <item>
      <title>Hello useContext!</title>
      <dc:creator>JustinBass</dc:creator>
      <pubDate>Thu, 09 Nov 2023 05:41:13 +0000</pubDate>
      <link>https://dev.to/justinbass/hello-usecontext-1oe5</link>
      <guid>https://dev.to/justinbass/hello-usecontext-1oe5</guid>
      <description>&lt;p&gt;&lt;strong&gt;W&lt;/strong&gt;hen first introduced to the world of React we tend to make our executions more complex than they need to be. Don't get me wrong, after only a year of studying software engineering my executions at times are more complex than needed. But isn't that the beauty of creating and building out code? Those aha moments?! I had a particular aha moment in the last application I built. It allowed me to realize why hooks can benefit the building process on the frontend of an application. This particular hook I'm speaking of is called &lt;strong&gt;&lt;em&gt;useContext&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;u&lt;/strong&gt;seContext allows us to share data between components without having to pass that data from a parent component to a child component to another child and so on. The process of passing data like so, is called &lt;strong&gt;&lt;em&gt;prop drilling&lt;/em&gt;&lt;/strong&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%2Fmy7m1mjmn0ry95yq3ihg.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%2Fmy7m1mjmn0ry95yq3ihg.jpeg" alt="Image description" width="800" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;bove we have a parent component &lt;em&gt;MoviePage&lt;/em&gt;. You can see that I have set a variable &lt;em&gt;selectedMovie&lt;/em&gt; with a value of a movie in the database based on a condition. I know I'm going to need this data for this parent's child, &lt;em&gt;ReviewCard&lt;/em&gt;. The reasoning behind this is when a review is deleted I can update the selected movie, its reviews, and set a new state for my movie's array and its relations. In my  &lt;em&gt;ReviewCard&lt;/em&gt; import I pass a prop called &lt;em&gt;selectedMovie&lt;/em&gt; equal to our variable &lt;em&gt;selectedMovie&lt;/em&gt;. This allows me to use the data from the parent in the &lt;em&gt;ReviewCard&lt;/em&gt; child component. I recommend keeping the prop naming conventions the same as the data variable or function names you are passing. As your app grows there's a good chance of easily getting confused with the data you're working with. Doing this will save you time from having to go back and forth between components to remind you of what's actually in front of you. &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%2Fgn7h47fzuonp45twvl9x.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%2Fgn7h47fzuonp45twvl9x.jpeg" alt="Image description" width="800" height="414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I&lt;/strong&gt;n our &lt;em&gt;ReviewCard&lt;/em&gt; child component we are destructuring our &lt;em&gt;selectedMovie&lt;/em&gt; prop. &lt;strong&gt;Don't forget to destruct your props!&lt;/strong&gt; I can't tell you how many times I've forgotten this one small detail and spent hours wondering why my execution wouldn't work. Now I'm able to use the data needed to update the selected movie, its reviews, and set a new state for my movie's array and its relations once a review is deleted. But is this truly considered prop drilling? Remember &lt;em&gt;prop drilling is having to pass data from a parent component to a child component to another child and so on.&lt;/em&gt; For this to be considered prop drilling, imagine that the &lt;em&gt;ReviewCard&lt;/em&gt; component has a child. This child was the actual component that needed the data from the &lt;em&gt;MoviePage&lt;/em&gt; component, which is the parent of &lt;em&gt;ReviewCard&lt;/em&gt;. We pass our prop from &lt;em&gt;MoviePage&lt;/em&gt; to &lt;em&gt;ReviewCard&lt;/em&gt; and pass the prop to this component's child. Ladies, gents, thems and theys... that is prop drilling at it's finest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;lthough prop drilling isn't completely frowned upon, &lt;em&gt;useContext&lt;/em&gt; can be used globally throughout your application and prevents the action of having to prop drill. A bonus that comes along with this hook is that it will make it easier to keep track of data you want to share with other components and calls for cleaner code. In my application, I have four models set up in the backend. &lt;em&gt;User, Movie, Review, and Reply&lt;/em&gt;. On the frontend, all of them will have their state set up for the data they retain. Now I could technically create one &lt;em&gt;provider component&lt;/em&gt; where I would create context for all models and set state for data like I did in a project when I first learned &lt;em&gt;useContext&lt;/em&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%2Fw7lwpn3xt0p6ynh09jzl.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%2Fw7lwpn3xt0p6ynh09jzl.jpeg" alt="Image description" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, given the &lt;em&gt;useState()&lt;/em&gt; setup, I was using one &lt;em&gt;provider component&lt;/em&gt; to set the context for all models and their data...🤭 If I'm being honest, I originally thought for useContext to work, the &lt;em&gt;provider component&lt;/em&gt; always had to be called &lt;code&gt;UserProvider&lt;/code&gt; and we set the state for all models and their data in this one &lt;em&gt;provider component&lt;/em&gt;. &lt;strong&gt;THIS IS WHY IT'S IMPORTANT TO RESEARCH AND ASK QUESTIONS!&lt;/strong&gt; Keep in mind you can name this &lt;em&gt;provider component&lt;/em&gt; whatever you'd like. However, &lt;code&gt;UserProvider&lt;/code&gt; makes sense because this component is technically providing data to other components who may need it. Naming it UserRocks would be a bit odd...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;R&lt;/strong&gt;emember &lt;strong&gt;convention over configuration&lt;/strong&gt; is best practice. Since I have a User, Movie, Review, and Reply model, I want to separate my concerns and give each of them its very own &lt;em&gt;provider component&lt;/em&gt; where context will be set for that particular class and its instances: &lt;/p&gt;

&lt;center&gt; &lt;b&gt; USER CONTEXT &lt;b&gt; &lt;/b&gt;&lt;/b&gt;
&lt;/center&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%2F0q0ko12zn3bl05k8ct8k.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%2F0q0ko12zn3bl05k8ct8k.jpeg" alt="Image description" width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;center&gt; &lt;b&gt; MOVIE CONTEXT &lt;b&gt; &lt;/b&gt;&lt;/b&gt;
&lt;/center&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%2F0d8snlv5b47011spuxcy.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%2F0d8snlv5b47011spuxcy.jpeg" alt="Image description" width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;center&gt; &lt;b&gt; REVIEW CONTEXT &lt;b&gt; &lt;/b&gt;&lt;/b&gt;
&lt;/center&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%2Fzu2zie1n6eemzxsqs4jk.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%2Fzu2zie1n6eemzxsqs4jk.jpeg" alt="Image description" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;center&gt; &lt;b&gt; REPLY CONTEXT &lt;b&gt; &lt;/b&gt;&lt;/b&gt;
&lt;/center&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%2Fonim81a1uwmzdva8wf5w.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%2Fonim81a1uwmzdva8wf5w.jpeg" alt="Image description" width="800" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ahhh, suddenly my anxiety has calmed down. 💁🏽&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;G&lt;/strong&gt;iving each model its own &lt;em&gt;provider component&lt;/em&gt; to set up context for their data allows for that separation of concern I mentioned earlier. This is where I can say 'Ok, I'm going to put all HTTP requests that relate to this particular model and its data and set state'. That way when the time comes I know exactly where to look, grab from, and update when working with a particular model and it's data in the backend from the frontend.&lt;/p&gt;

&lt;center&gt; &lt;b&gt; "VALUE" PROP &lt;b&gt; &lt;/b&gt;&lt;/b&gt;
&lt;/center&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%2Fvzx5fjx7cqecmdhhooch.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%2Fvzx5fjx7cqecmdhhooch.jpeg" alt="Image description" width="800" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notice&lt;/strong&gt; in the return of our &lt;em&gt;provider components&lt;/em&gt; we have what looks like a prop called value. Well, &lt;strong&gt;that's because it is a prop and any child of a &lt;em&gt;provider component&lt;/em&gt; has access to that prop and its values!&lt;/strong&gt; Now what exactly are we setting the values to in this prop? Data that can be or needs to be shared with other components. Maybe something equivalent to an array of all movies that the Movie model holds in our backend or even an array of all the reviews that the Review model holds:&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%2F8h6s1onm8x6el7xdzjgz.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%2F8h6s1onm8x6el7xdzjgz.jpeg" alt="Image description" width="800" height="436"&gt;&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%2Ftnphz4ex1gvunwozwce1.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%2Ftnphz4ex1gvunwozwce1.jpeg" alt="Image description" width="800" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the snaps above I'm using a &lt;em&gt;useEffect()&lt;/em&gt; to send a fetch to a registered route in the back end that will then be mapped to a controller action to render back JSON of all movies in the Movie model database. Within that fetch, I'm setting the movies into an empty array called 'movies' using state. Great, now I have the data I need for movies to render them to the front end. I might just need that array of movies for other purposes rather than just rendering the title, poster, year, and the cast of the movie. So I want to make context out of this array to possibly share this data with other child components that need it. More on that a bit later. I then pass that data under 'movies' as a prop under 'value=' in the case that I do need this data for child components. &lt;/p&gt;

&lt;center&gt; &lt;b&gt; Provider Components have child components say whaaa????  &lt;b&gt; &lt;/b&gt;&lt;/b&gt;
&lt;/center&gt;

&lt;p&gt;&lt;strong&gt;W&lt;/strong&gt;ell, how do we make &lt;em&gt;provider components&lt;/em&gt; and their prop data available to other components within our app if technically it has no child components? Well, it doesn't have any children yet because we haven't given it any children. In our earlier example with &lt;em&gt;MoviePage&lt;/em&gt; and &lt;em&gt;ReviewCard&lt;/em&gt; I was able to share the data that the &lt;em&gt;MoviePage&lt;/em&gt; has and pass it onto &lt;em&gt;ReviewCard&lt;/em&gt; as a prop because &lt;em&gt;ReviewCard&lt;/em&gt; is its child! We imported &lt;em&gt;ReviewCard&lt;/em&gt; into the &lt;em&gt;MoviePage&lt;/em&gt; component and rendered whatever code is set up in &lt;em&gt;ReviewCard&lt;/em&gt; from the &lt;em&gt;MoviePage&lt;/em&gt; making ReviewC its child. However, without the data provided by the &lt;em&gt;MoviePage&lt;/em&gt; what originally was supposed to render visually to the user would not have been possible. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;S&lt;/strong&gt;o if we want all components to have access to a provider component data we need to ensure that the provider components are wrapped around the top-level component of our application. To do so we need to import all provider components we'd like data from into our top-level component of the application and then proceed to wrap:&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%2Fx5ch47jwr6j3usoifvxp.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%2Fx5ch47jwr6j3usoifvxp.jpeg" alt="Image description" width="800" height="553"&gt;&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%2Fk3n2149mjkp33v75kjfz.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%2Fk3n2149mjkp33v75kjfz.jpeg" alt="Image description" width="800" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Voila!&lt;/strong&gt; There you have it, &lt;em&gt;useContext&lt;/em&gt; is set and ready to go! &lt;em&gt;No more prop drilling&lt;/em&gt;. But how do we use &lt;em&gt;useContext&lt;/em&gt; throughout our child components? Let's say I have settings in my application where a user can update their username or user image:&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%2Fi0nj7p6dfuatfkyx6mxg.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%2Fi0nj7p6dfuatfkyx6mxg.jpeg" alt="Image description" width="800" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sure we can request the backend to update the user info through a fetch and change the user state, but what if we have a movie that has many reviews and these reviews render with an image and the username of the user who left the review?&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%2Fcez08zciho9am9twra8q.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%2Fcez08zciho9am9twra8q.jpeg" alt="Image description" width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We'd have to update the movie's state within that fetch request. This is where the realization of how great &lt;em&gt;useContext&lt;/em&gt; is. &lt;/p&gt;

&lt;center&gt; &lt;b&gt; useContext IN ACTION &lt;b&gt; &lt;/b&gt;&lt;/b&gt;
&lt;/center&gt;

&lt;p&gt;In my UserProvider component, I have fetches set up to update a user username and a user image:&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%2Fs02ftjbskogrxywlx24s.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%2Fs02ftjbskogrxywlx24s.jpeg" alt="Image description" width="800" height="752"&gt;&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%2F8b2n2t52ruil55hdf98t.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%2F8b2n2t52ruil55hdf98t.jpeg" alt="Image description" width="800" height="761"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I know because a movie has many reviews and these reviews are rendered with an image and the username of the user who left the review I will have to update my movies state. Let's say in theory I had set up the state of movies in the top-level component of my application. I might have to prop-drill the movie data down until I reached the child component I need to get to in order to update a state within this fetch. Because I set up context for my movie data I can easily import &lt;em&gt;useContext&lt;/em&gt; and &lt;em&gt;MovieContext&lt;/em&gt; into the child component of &lt;em&gt;MovieContext&lt;/em&gt;, &lt;em&gt;User_Profile&lt;/em&gt;. I also destructed my 'prop' &lt;em&gt;{ movies } equal to useContext( MovieContext )&lt;/em&gt;. Remember, every provider component holds a &lt;em&gt;'value' prop&lt;/em&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%2Fldeul3s0g6i15yzjdm8l.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%2Fldeul3s0g6i15yzjdm8l.jpeg" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also imported &lt;em&gt;UserContext&lt;/em&gt; into my &lt;em&gt;User_Profile&lt;/em&gt; component &lt;em&gt;(a child of UserProvider)&lt;/em&gt; and destructed my props &lt;em&gt;updateUsername&lt;/em&gt; and &lt;em&gt;updateUserImage&lt;/em&gt; that hold a value of my fetch POST functions in &lt;em&gt;UserProvider&lt;/em&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%2F8x25ogybo9kkvfxuuzan.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%2F8x25ogybo9kkvfxuuzan.jpeg" alt="Image description" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look back at my fetch POST functions set up in &lt;em&gt;UserProvider&lt;/em&gt; you can see it takes in a movies argument. You can see now because I imported &lt;em&gt;useContext&lt;/em&gt;, &lt;em&gt;MovieContext&lt;/em&gt;, and destructed my movies prop I'm able to pass in the movie data into my &lt;em&gt;updateUsernameSubmit&lt;/em&gt; and &lt;em&gt;updateUserImageSubmit&lt;/em&gt; functions for my form onSubmit events: &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%2Fbm2jros5l5b780cvprbc.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%2Fbm2jros5l5b780cvprbc.jpeg" alt="Image description" width="800" height="236"&gt;&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%2Fvgapa244mffow2isz801.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%2Fvgapa244mffow2isz801.jpeg" alt="Image description" width="800" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will allow for an update on the state of movies so when a user updates their username or image not only will you seen an update on the users profile but also an update on a movies reviews. And guess what?! No &lt;strong&gt;PROP DRILLING!&lt;/strong&gt;:&lt;/p&gt;

&lt;center&gt; &lt;b&gt; BEFORE UPDATE &lt;b&gt; &lt;/b&gt;&lt;/b&gt;
&lt;/center&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%2Fgs17t7gpkfa1yomebzt6.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%2Fgs17t7gpkfa1yomebzt6.jpeg" alt="Image description" width="800" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;center&gt; &lt;b&gt; AFTER UPDATE &lt;b&gt; &lt;/b&gt;&lt;/b&gt;
&lt;/center&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%2F6oqihkyt4sf9bqrd5hux.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%2F6oqihkyt4sf9bqrd5hux.jpeg" alt="Image description" width="800" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RESOURCES&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/context-api-in-react/#:~:text=It's%20important%20to%20note%20that,access%20to%20the%20shared%20data."&gt;freeCodecamp&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://legacy.reactjs.org/docs/context.html"&gt;React&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Let's talk validations.</title>
      <dc:creator>JustinBass</dc:creator>
      <pubDate>Mon, 18 Sep 2023 19:35:27 +0000</pubDate>
      <link>https://dev.to/justinbass/lets-talk-validations-5gfe</link>
      <guid>https://dev.to/justinbass/lets-talk-validations-5gfe</guid>
      <description>&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;s the title states, it's time to talk about validations. What does it mean to validate or to be validated? To keep it short and simple, it is &lt;em&gt;the action of checking or proving the validity or accuracy of something.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I&lt;/strong&gt;n the world of cyber technology, I believe as users of platforms such as Facebook, Instagram, and X (formerly known as Twitter) we don't realize or come to the idea that we are always passing or failing validation checks. For example, if we attempt to sign in to our Facebook account with a valid email but forget to enter our password, we as the user might receive a message stating 'Username or password is invalid'. For the average user, it may not spark enough interest to dive deeper and understand what is causing this particular error. But as passionate coders, our minds start running beyond miles to truly understand and hone in on how the magic of such an error can occur.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I&lt;/strong&gt;n general, a lie would be exposed if a statement was made that we as humans don't like being 'validated' for how we believe things should be executed to prevent mishaps. We have all had roommates in our lifetime at some point. Let's paint a picture here. We have two roommates living together. Roommate one likes using top-notch paper towels because they believe it cleans the best when wiping down counters. Roommate two likes using top-notch dish soap because they believe it clears a high volume of oil off of greasy pots. If roommate two buys cheap paper towels, a conflict might arise with roommate one blocking roommate two from using the paper towels they just bought. Why? Because roommate one does not approve of paper towels that are not of good quality. They believe it won't do the job of thoroughly cleaning the countertops. Visa versa, if roommate one buys cheap dish soap, a conflict might arise with roommate two giving the same outcome as the first scenario.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;J&lt;/strong&gt;ust how it would work with our roommate scenario and the conflicts that come along with it, validations in the cyber world work in similar ways. So how do the examples above relate to Ruby on Rails validations? Relating back to the example of logging in to a platform with a valid email but an empty input field for a password, we as the user are blocked from gaining access to our account. Facebook (roommate one) does not approve of the user (roommate two) not having a password or a valid password. In return, Facebook responds and says 'No way am I giving you access to an actual account, the values given do not match the credentials of the user you say or think you are'. A conflict is then raised between the user and the platform. When the user (roommate two) provides a password that passes a credential check, Facebook (roommate one) will validate and approve the user moving forward with the actions they want to fulfill.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;V&lt;/strong&gt;alidations with Ruby on Rails are used to ensure data sent through an HTTP request from the client (such as logging in or signing into an account with a username and password) are valid to save to the backends database. If the username and password are not valid this would be considered an &lt;em&gt;unprocessable entity&lt;/em&gt;. Validations are &lt;em&gt;helper methods&lt;/em&gt;, they help the backend prevent bad data from being saved to the database. These helper methods live within our classes so we can specify exactly what attributes within the instances of these classes we want to set validations on.&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%2Fc1qpcvo8m43fwp8oj7y3.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%2Fc1qpcvo8m43fwp8oj7y3.jpeg" alt="Image description" width="800" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I&lt;/strong&gt;n the example above we have a &lt;em&gt;User class&lt;/em&gt; that utilizes validation helper methods for attributes on a given instance of the class. The first two validations are set up for the attribute &lt;em&gt;username&lt;/em&gt; within the instance. &lt;em&gt;Presence&lt;/em&gt; ensures that a username does exist in the login or signup input field (the field can not be left empty). &lt;em&gt;Uniqueness&lt;/em&gt; ensures that a username can't be used more than once, meaning if I sign up for Facebook under &lt;em&gt;JustenBass5678&lt;/em&gt;, when another user signs up and tries using the exact same username they will get an error on the front end. Let's take a look at how this would look on the client side.&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%2Fawcu680rbv820qoia69o.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%2Fawcu680rbv820qoia69o.jpeg" alt="Image description" width="800" height="571"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;bove we have a signup input field for a user creating a new account on a platform. If we submit this form with the username being blank we should get an error due to the &lt;em&gt;presence&lt;/em&gt; validation helper method set up in our User class:&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%2F16sc7fqou0ldxd8kqdg9.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%2F16sc7fqou0ldxd8kqdg9.jpeg" alt="Image description" width="800" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;n error should also occur on the client side if we signup with a username that already exists for another user due to the &lt;em&gt;uniqueness&lt;/em&gt; validation helper method set up in our User class:&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%2F495lvnb4fvlaevhd6rxt.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%2F495lvnb4fvlaevhd6rxt.jpeg" alt="Image description" width="800" height="528"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I&lt;/strong&gt;f we as the user change our username from &lt;em&gt;JustenBass5678&lt;/em&gt; to &lt;em&gt;JustenBass22&lt;/em&gt;, we should meet all the credentials for the validations set in our User class and gain full access to our new account:&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%2F7e8ss4o704fc92e803hx.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%2F7e8ss4o704fc92e803hx.jpeg" alt="Image description" width="800" height="535"&gt;&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%2Fqi5dg63rq5g8c7nweaxm.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%2Fqi5dg63rq5g8c7nweaxm.jpeg" alt="Image description" width="800" height="362"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;V&lt;/strong&gt;alidations are key for preventing bad data from getting saved into a database. However, it also plays a huge role in security. If Facebook allowed all its users to have the same username it would open a wide door for potential hacking. All it would take is another user having the same username to guess the correct password of another user's account and BAM, they are in. What if the platform wasn't Facebook and it was a Chase Bank account? Then a user can possibly gain access to another user's important financial documentation. Sure it could take some time for a hacker to guess the right password but is possible. You can only imagine the many different ideas and theories on the importance of validations. Just know they are IMPORTANT! For more information on validations and other validations you can take advantage of, check out &lt;a href="https://guides.rubyonrails.org/active_record_validations.html"&gt;Rails Guides: Active Record Validations&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Resources&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1:&lt;/strong&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions"&gt;Rails Guides: Active Record Validations&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>CLASSES, INSTANCES, SETTERS, GETTERS, MARCOS... SAY WHAAA?!</title>
      <dc:creator>JustinBass</dc:creator>
      <pubDate>Wed, 14 Jun 2023 01:50:12 +0000</pubDate>
      <link>https://dev.to/justinbass/class-instance-setters-getters-marcos-say-whaaa-mh0</link>
      <guid>https://dev.to/justinbass/class-instance-setters-getters-marcos-say-whaaa-mh0</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;center&gt;A WALK THROUGH TO REMEMBER&lt;/center&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;center&gt;&lt;/center&gt;

&lt;p&gt;Just when you thought JavaScript and React would throw you for a loop, you thought wrong... &lt;em&gt;Ruby&lt;/em&gt; decided to swing by and say "Hey girl, hey!". It's not that &lt;em&gt;Ruby&lt;/em&gt; is extremely difficult to take on, it's the idea of having to rewire your mind to tackle a whole new coding language. After all, no one said this would be an easy task. &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%2F5ckkuz2011ruoep1y5cd.gif" 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%2F5ckkuz2011ruoep1y5cd.gif" alt="Image description" width="298" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I, and I'm sure many coders, can describe the beginning of learning  &lt;em&gt;Object Oriented Programming&lt;/em&gt; as shown in the example above. One fighting so hard to grasp the concepts of &lt;em&gt;OOP&lt;/em&gt; while having to take a few tumbles before allowing ourselves the time and patience to become one with the language. Let's be honest, this language is significantly bigger than ours and has extraordinary pro behaviors. However, we all must start somewhere and the key to starting "somewhere" is truly understanding the fundamentals and terminology in which we one day dream to master.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;center&gt;CLASSES AND INSTANCES IN OBJECT ORIENTED PROGRAMMING&lt;/center&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;center&gt;&lt;/center&gt;

&lt;p&gt;• A &lt;strong&gt;&lt;code&gt;class&lt;/code&gt;&lt;/strong&gt; in &lt;em&gt;OOP&lt;/em&gt; are models of the program that act as a blueprint for our objects &lt;em&gt;&lt;code&gt;(an instance)&lt;/code&gt;&lt;/em&gt;, the object's &lt;code&gt;attributes&lt;/code&gt;, and methods that we can use on our &lt;code&gt;class&lt;/code&gt; itself or &lt;code&gt;instances&lt;/code&gt; of that &lt;code&gt;class&lt;/code&gt;. That's right, there are &lt;code&gt;class methods&lt;/code&gt; and &lt;code&gt;instance methods&lt;/code&gt;. More on &lt;code&gt;class methods&lt;/code&gt; in future lessons! 😉&lt;/p&gt;

&lt;center&gt;&lt;/center&gt;

&lt;p&gt;• An &lt;strong&gt;&lt;code&gt;instance&lt;/code&gt;&lt;/strong&gt; in &lt;em&gt;OOP&lt;/em&gt; are objects &lt;em&gt;&lt;code&gt;(an instance)&lt;/code&gt;&lt;/em&gt; of our &lt;code&gt;class&lt;/code&gt; that holds detailed data about oneself acquired from &lt;code&gt;attributes&lt;/code&gt; that are set with values after a new &lt;code&gt;instance&lt;/code&gt; is &lt;code&gt;instantiated&lt;/code&gt;.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;center&gt;CLASS VISIUAL&lt;/center&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;center&gt;&lt;/center&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%2Fx51adfldwrbviaxfowog.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%2Fx51adfldwrbviaxfowog.jpeg" alt="Image description" width="800" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;QUIZ TIME!!!&lt;/strong&gt;&lt;br&gt;
What is a &lt;code&gt;class&lt;/code&gt; in &lt;em&gt;OOP&lt;/em&gt;?&lt;br&gt;
&lt;strong&gt;&lt;em&gt;A blueprint for our objects(&lt;code&gt;an instance&lt;/code&gt;), the object's &lt;code&gt;attributes&lt;/code&gt;, and methods that we can use on our &lt;code&gt;class&lt;/code&gt; itself or instances of that &lt;code&gt;class&lt;/code&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we jump into the visual of an &lt;code&gt;instance&lt;/code&gt; it's crucial to know the work a &lt;code&gt;class&lt;/code&gt; executes under the hood in order to &lt;code&gt;instantiate&lt;/code&gt; an &lt;code&gt;instance&lt;/code&gt; of a &lt;code&gt;class&lt;/code&gt;. What exactly does it take to &lt;code&gt;instantiate&lt;/code&gt; an &lt;code&gt;instance&lt;/code&gt; of a &lt;code&gt;class&lt;/code&gt;? We know that an &lt;code&gt;instance&lt;/code&gt; &lt;em&gt;holds detailed data about oneself acquired from &lt;code&gt;attributes&lt;/code&gt; that are set with values after a new &lt;code&gt;instance&lt;/code&gt; is&lt;/em&gt; &lt;code&gt;instantiated&lt;/code&gt;. But how would it be possible for our &lt;code&gt;instance&lt;/code&gt; to know about its &lt;code&gt;attributes&lt;/code&gt; when &lt;code&gt;instantiated&lt;/code&gt;? This is when the &lt;em&gt;extraordinary pro behaviors&lt;/em&gt; of &lt;em&gt;OOP&lt;/em&gt; take center stage.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;center&gt;CLASS VISIUAL: SETTER AND GETTER INSTANCE METHODS&lt;/center&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;center&gt;&lt;/center&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%2Ftq4qbg3dipfj1xk3tfkg.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%2Ftq4qbg3dipfj1xk3tfkg.jpeg" alt="Image description" width="800" height="218"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;•A &lt;strong&gt;&lt;code&gt;setter method&lt;/code&gt;&lt;/strong&gt; is an &lt;code&gt;instance method&lt;/code&gt;. Using this method allows us to set an &lt;code&gt;attribute&lt;/code&gt; with a value of our &lt;code&gt;Person class instance&lt;/code&gt; post &lt;code&gt;instantiation&lt;/code&gt;. You may be looking at &lt;code&gt;@name&lt;/code&gt; and thinking to yourself "Well that looks familiar, it's a variable!". Yes, like JavaScript this is a variable without a &lt;code&gt;var, const, or let&lt;/code&gt; but instead begins with an &lt;code&gt;@&lt;/code&gt; attached to the variable name. &lt;code&gt;@name&lt;/code&gt; is known as an &lt;code&gt;instance variable&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;@name&lt;/code&gt; becomes an &lt;code&gt;attribute&lt;/code&gt; available to an &lt;code&gt;instance&lt;/code&gt; of the &lt;code&gt;Person class&lt;/code&gt;. In this case, our &lt;code&gt;instance&lt;/code&gt; can have an &lt;code&gt;attribute&lt;/code&gt; of &lt;code&gt;name&lt;/code&gt; that we can set equal to a &lt;code&gt;'string' value&lt;/code&gt; &lt;em&gt;(or any data type value. In our case a name in real life, would be set to a 'string' data type)&lt;/em&gt; after we &lt;code&gt;instantiate&lt;/code&gt; a new &lt;code&gt;instance&lt;/code&gt; of the &lt;code&gt;Person class&lt;/code&gt;. However, a &lt;code&gt;setter method&lt;/code&gt; couldn’t be used to its best ability without its side kick...&lt;code&gt;getter method&lt;/code&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%2Fe9axpyk9eolpi3mpghi3.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%2Fe9axpyk9eolpi3mpghi3.jpeg" alt="Image description" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;• A &lt;strong&gt;&lt;code&gt;getter method&lt;/code&gt;&lt;/strong&gt; is a method of an &lt;code&gt;instance&lt;/code&gt; and pairs perfectly with a &lt;code&gt;setter method&lt;/code&gt;. Think of the &lt;code&gt;setter method&lt;/code&gt; as a &lt;em&gt;writer&lt;/em&gt;. Its job is to take in an argument through its parameter, &lt;em&gt;write&lt;/em&gt; it to the &lt;code&gt;instance variable @name&lt;/code&gt;, and store it away in memory. Let's take a look at what would happen if we &lt;code&gt;instantiate&lt;/code&gt; an &lt;code&gt;instance&lt;/code&gt; of the &lt;code&gt;Person class&lt;/code&gt; without a &lt;code&gt;getter method&lt;/code&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%2Fhfjj3771d19iq05itnk2.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%2Fhfjj3771d19iq05itnk2.jpeg" alt="Image description" width="800" height="218"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;• Above we have our Person class set with just a setter method that creates an attribute with an instance variable. Now it's time to instantiate an instance of the Person class and set its name attribute equal to a 'string' value:&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%2Fnaw3lap7dij4b4kll9eg.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%2Fnaw3lap7dij4b4kll9eg.jpeg" alt="Image description" width="800" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;• Here we’re saving our new &lt;code&gt;instantiated instance&lt;/code&gt; to a &lt;code&gt;local variable&lt;/code&gt; called &lt;code&gt;justin&lt;/code&gt;. We then take that variable with a value of our new &lt;code&gt;instance&lt;/code&gt; and call it on our &lt;code&gt;setter method&lt;/code&gt; within our &lt;code&gt;Person class&lt;/code&gt;, &lt;code&gt;name=&lt;/code&gt;. Remember the &lt;code&gt;setter method&lt;/code&gt; has the &lt;em&gt;responsibility to take in an argument through its parameter, &lt;strong&gt;write&lt;/strong&gt; it to the &lt;code&gt;instance variable @name&lt;/code&gt;, and store it away in memory&lt;/em&gt;. Although we would be able to set the &lt;code&gt;name attribute&lt;/code&gt; for our new &lt;code&gt;instance&lt;/code&gt; given the &lt;code&gt;setter method "name="&lt;/code&gt;, what would happen if we called our &lt;code&gt;instance&lt;/code&gt; on &lt;code&gt;justin.name&lt;/code&gt; in order to see the &lt;code&gt;name value&lt;/code&gt; of the &lt;code&gt;attribute&lt;/code&gt; within the &lt;code&gt;instance&lt;/code&gt; assigned:&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%2Fot9hda7x1goagn5wbv6b.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%2Fot9hda7x1goagn5wbv6b.jpeg" alt="Image description" width="800" height="56"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;•As you can see from the example above, we would get an error stating &lt;code&gt;"NoMethodError: undefined method 'name' for #&amp;lt;Person:0x000000011d969bf0 @name="Justin"&amp;gt;&lt;br&gt;
Did you mean?  name="&lt;/code&gt;. When one sees &lt;code&gt;NoMethodError&lt;/code&gt; we should assume as a coder there is no method existing that we can call this &lt;code&gt;instance&lt;/code&gt; on. This is why the error is asking us "&lt;code&gt;Did you mean?  name=&lt;/code&gt;".  Keep in mind &lt;code&gt;name=&lt;/code&gt; being the &lt;code&gt;setter method&lt;/code&gt;, is a completely different call than &lt;code&gt;name&lt;/code&gt; being the &lt;code&gt;getter method&lt;/code&gt;. Let's bring the &lt;code&gt;getter method&lt;/code&gt; back into the equation of our &lt;code&gt;Person class&lt;/code&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%2Fny3rs2lpl81zdpi5uwg6.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%2Fny3rs2lpl81zdpi5uwg6.jpeg" alt="Image description" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;•Now what would happen if we called our new &lt;code&gt;instantiated instance&lt;/code&gt; on &lt;code&gt;justin.name&lt;/code&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%2F76u3f8et55ytjqnvxszj.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%2F76u3f8et55ytjqnvxszj.jpeg" alt="Image description" width="420" height="62"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;•As mentioned &lt;em&gt;&lt;code&gt;name=&lt;/code&gt; being the &lt;code&gt;setter method&lt;/code&gt;, is a completely different call than &lt;code&gt;name&lt;/code&gt; being the &lt;code&gt;getter method&lt;/code&gt;&lt;/em&gt;. This is why a &lt;code&gt;setter method&lt;/code&gt; and a &lt;code&gt;getter method&lt;/code&gt; go hand and hand.  A &lt;code&gt;setter method&lt;/code&gt; is a &lt;em&gt;writer&lt;/em&gt;. Its job is to &lt;em&gt;take in an argument through its parameter, and _write&lt;/em&gt; it to the &lt;code&gt;instance variable @name&lt;/code&gt;&lt;em&gt;. A &lt;code&gt;getter method&lt;/code&gt; is a _reader&lt;/em&gt;.  Its job is to &lt;em&gt;read&lt;/em&gt; what the &lt;code&gt;setter method&lt;/code&gt; saved in memory for us, to the world.&lt;/p&gt;

&lt;p&gt;Without both &lt;code&gt;instance methods&lt;/code&gt; working together we wouldn't have the full functionality we desire!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;center&gt;SETTER AND GETTER METHODS: MARCOS&lt;/center&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;center&gt;&lt;/center&gt;

&lt;p&gt;It may seem tedious to explicitly code out &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter methods&lt;/code&gt; within a class every time we'd want to set a new &lt;code&gt;instance&lt;/code&gt; with an &lt;code&gt;attribute&lt;/code&gt;. Surely, there has to be an easier way to write out both methods. If there is a will, there is most definitely a way. What is another method we could use that essentially is a &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter method&lt;/code&gt;? Drum roll, please!!! 🥁 &lt;code&gt;MARCOS&lt;/code&gt;!!!``&lt;/p&gt;

&lt;p&gt;• A &lt;strong&gt;&lt;code&gt;marco&lt;/code&gt;&lt;/strong&gt;, is an &lt;code&gt;instance method&lt;/code&gt; that &lt;code&gt;implicitly&lt;/code&gt; represents our &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter methods&lt;/code&gt;. Marcos allows the representation of both methods individually or in a lump sum. Are you confused yet? Let's break it down!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;center&gt;MARCOS SETTER AND GETTER METHODS VISUAL: MARCOS REPRESENTING ONE&lt;/center&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;center&gt;&lt;/center&gt;

&lt;p&gt;A &lt;code&gt;marco&lt;/code&gt; can represent both a &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter&lt;/code&gt; individually. Typically it's best to start with a &lt;code&gt;setter method&lt;/code&gt; within a &lt;code&gt;class model&lt;/code&gt;. Our &lt;code&gt;setter method&lt;/code&gt; is what allows us to create an &lt;code&gt;attribute&lt;/code&gt; that our &lt;code&gt;instance&lt;/code&gt; of the current &lt;code&gt;class&lt;/code&gt; can adopt. We'll stick with our &lt;code&gt;name attribute&lt;/code&gt; for this &lt;code&gt;instance&lt;/code&gt;. Here's an example of a &lt;code&gt;marco&lt;/code&gt; representing a &lt;code&gt;setter method implicitly&lt;/code&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%2F6r2h0lyowfstazrv2dbe.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%2F6r2h0lyowfstazrv2dbe.jpeg" alt="Image description" width="644" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's important to know and understand a &lt;code&gt;setter method&lt;/code&gt; is a &lt;em&gt;writer&lt;/em&gt;. &lt;em&gt;Its job is to take in an argument through its parameter, _write&lt;/em&gt; it to the &lt;code&gt;instance variable @name&lt;/code&gt;, and store it away in memory_. The same exception happens &lt;code&gt;implicitly&lt;/code&gt; with &lt;code&gt;marcos&lt;/code&gt;. As shown in the example above, the &lt;code&gt;marco&lt;/code&gt; syntax for a &lt;code&gt;setter method&lt;/code&gt; is &lt;code&gt;"attr_writer :attribute_name"&lt;/code&gt;. All &lt;code&gt;attribute&lt;/code&gt; names within this syntax must begin with a &lt;code&gt;colon&lt;/code&gt;. We should now know if calling this method on an &lt;code&gt;instance&lt;/code&gt;, the &lt;code&gt;instance&lt;/code&gt; will adopt a name &lt;code&gt;attribute&lt;/code&gt; when given a value equal to a &lt;code&gt;'string'&lt;/code&gt; datatype:&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%2Flu3f0vcfz4jcsukdpuzo.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%2Flu3f0vcfz4jcsukdpuzo.jpeg" alt="Image description" width="636" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Intuitively, we know if we call our &lt;code&gt;instance&lt;/code&gt; on &lt;code&gt;justin.name&lt;/code&gt; in order to see the &lt;code&gt;name value&lt;/code&gt; of the &lt;code&gt;attribute&lt;/code&gt; on our &lt;code&gt;instance&lt;/code&gt;, we would get an error stating &lt;code&gt;"NoMethodError: undefined method 'name' for #&amp;lt;Person:0x000000011d969bf0 @name="Justin"&amp;gt;&lt;br&gt;
Did you mean?  name="&lt;/code&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%2Fe6kue2oak8iwfuh7vnbx.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%2Fe6kue2oak8iwfuh7vnbx.jpeg" alt="Image description" width="800" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;QUIZ TIME!!!&lt;/strong&gt;&lt;br&gt;
Why are we getting the error &lt;code&gt;"NoMethodError: undefined method 'name' for #&amp;lt;Person:0x000000011d969bf0 @name="Justin"&amp;gt;&lt;br&gt;
Did you mean?  name="&lt;/code&gt;?&lt;br&gt;
&lt;strong&gt;&lt;em&gt;There is no method that exists that we can call this instance on!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This tells us we need a &lt;code&gt;marco&lt;/code&gt; that &lt;code&gt;implicitly&lt;/code&gt; represents a &lt;code&gt;getter method&lt;/code&gt; within our &lt;code&gt;Person class&lt;/code&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%2F7k1m37vanf5lie6k1k3e.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%2F7k1m37vanf5lie6k1k3e.jpeg" alt="Image description" width="660" height="197"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;marco&lt;/code&gt; syntax for a &lt;code&gt;getter method&lt;/code&gt; is similar to the syntax for a &lt;code&gt;setter method&lt;/code&gt; with a slight difference. Recall that a &lt;code&gt;getter method&lt;/code&gt; acts as a &lt;em&gt;reader&lt;/em&gt;. &lt;em&gt;Its job is to _read&lt;/em&gt; what the &lt;code&gt;setter method&lt;/code&gt; saved in memory for us, to the world._ With that being said, what do you think the &lt;code&gt;marco&lt;/code&gt; syntax would be for a &lt;code&gt;getter method&lt;/code&gt;? Keep in mind the syntax will always start with &lt;code&gt;attr_&lt;/code&gt;. This makes sense seeing that we're setting up an &lt;code&gt;attribute&lt;/code&gt; within the &lt;code&gt;Person class&lt;/code&gt; for our future &lt;code&gt;instances&lt;/code&gt;. If the syntax for a &lt;code&gt;setter method&lt;/code&gt; is &lt;code&gt;attr_writer&lt;/code&gt; with &lt;code&gt;writer&lt;/code&gt; being the &lt;em&gt;key&lt;/em&gt; word, what is a &lt;em&gt;key&lt;/em&gt; word that describes a &lt;code&gt;getter&lt;/code&gt;? &lt;strong&gt;READER&lt;/strong&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%2Flxk5smroshwzq625q4mu.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%2Flxk5smroshwzq625q4mu.jpeg" alt="Image description" width="660" height="197"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice we still need to include the name of the &lt;code&gt;attribute&lt;/code&gt; beginning with a &lt;code&gt;colon&lt;/code&gt; for our &lt;code&gt;implicit&lt;/code&gt; &lt;code&gt;getter method&lt;/code&gt; provided by &lt;code&gt;marcos&lt;/code&gt;. If we think back to the &lt;code&gt;explicit&lt;/code&gt; versions of our &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter&lt;/code&gt; in the &lt;code&gt;Person class&lt;/code&gt;, both methods had a representation of the &lt;code&gt;instance variable @name&lt;/code&gt;. This is crucial seeing that it helps keep the flow of &lt;code&gt;reading&lt;/code&gt; and &lt;code&gt;writing&lt;/code&gt; our &lt;code&gt;attributes&lt;/code&gt; in sync. Now it's time to put our tag team &lt;code&gt;marcos&lt;/code&gt; to the test!:&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%2Flvo29elmw4n7fiyhfa35.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%2Flvo29elmw4n7fiyhfa35.jpeg" alt="Image description" width="630" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If this isn't magic, I don't know what is! We were able to &lt;code&gt;initiate&lt;/code&gt; an &lt;code&gt;attribute&lt;/code&gt; for our future &lt;code&gt;instances&lt;/code&gt; of our &lt;code&gt;Person class&lt;/code&gt; given the &lt;code&gt;marco setter method&lt;/code&gt;. Even more, we gracefully &lt;em&gt;read&lt;/em&gt; the value of the &lt;code&gt;attribute&lt;/code&gt; to the world given our &lt;code&gt;marco getter method&lt;/code&gt;. Job well done! However as coders, any opportunity given where we can make our code excel in ways we never thought possible, we take it! Although &lt;code&gt;marcos&lt;/code&gt; is short-hand for writing explicit &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter methods&lt;/code&gt;, you would think there's one &lt;code&gt;marco&lt;/code&gt; syntax that would implicitly set up both methods for us in lump sum. Bust out your inhalers because you'll be shocked that there is!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;center&gt;MARCOS SETTER AND GETTER METHODS VISUAL: MARCOS REPRESENTING BOTH LUMP SUM&lt;/center&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;center&gt;&lt;/center&gt;

&lt;p&gt;I know what you may be thinking if you're new to the coding world. &lt;em&gt;"WHY IN THE WORLD DID YOU NOT EXPLAIN MARCOS IN THE FIRST PLACE!"&lt;/em&gt; I get it. Yes, &lt;code&gt;marcos&lt;/code&gt; is an easier set up than &lt;code&gt;explicit setter&lt;/code&gt; and &lt;code&gt;getter methods&lt;/code&gt;. However, &lt;em&gt;&lt;strong&gt;we all must start somewhere and the key to starting "somewhere" is truly understanding the fundamentals and terminology in which we one day dream to master&lt;/strong&gt;&lt;/em&gt;. Without understanding the fundamentals and terminology from which a method truly stems, how do we expect to understand how the &lt;em&gt;"easier"&lt;/em&gt; way of doing things actually works? Especially when it's implicit. You know what they say! Slow and steady wins the race.&lt;/p&gt;

&lt;p&gt;If you made it this far and truly have a grasp on the concepts of a &lt;code&gt;class&lt;/code&gt;, &lt;code&gt;instance&lt;/code&gt;, the origin of &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter&lt;/code&gt; methods, please indulge in our final &lt;code&gt;marco&lt;/code&gt; that implicitly represents both a &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter&lt;/code&gt; lump sum.&lt;/p&gt;

&lt;p&gt;Let me introduce to you &lt;code&gt;attr_accessor&lt;/code&gt;. The &lt;code&gt;marco&lt;/code&gt; &lt;code&gt;attr_accessor&lt;/code&gt; allows for a &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter method&lt;/code&gt; to be grouped into one &lt;code&gt;marco&lt;/code&gt;. We no longer need to write two separate &lt;code&gt;marcos&lt;/code&gt;, only one &lt;code&gt;marco&lt;/code&gt; saving us time:&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%2Facbuj10xpfvqn5hrpwvy.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%2Facbuj10xpfvqn5hrpwvy.jpeg" alt="Image description" width="650" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice with this syntax we still need to apply a &lt;code&gt;colon&lt;/code&gt; followed by the &lt;code&gt;attribute&lt;/code&gt; name. With our &lt;code&gt;Parent class&lt;/code&gt; and &lt;code&gt;marco attr_accessor&lt;/code&gt; set up lets &lt;code&gt;instantiate' a new &lt;/code&gt;instance&lt;code&gt; of our &lt;/code&gt;class&lt;code&gt; saved to the variable, &lt;/code&gt;justin`:&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%2Fa0798rizbh68rzvde2kf.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%2Fa0798rizbh68rzvde2kf.jpeg" alt="Image description" width="652" height="69"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As with our &lt;code&gt;explicit&lt;/code&gt; and &lt;code&gt;implicit&lt;/code&gt; methods before, our next step would be to take the variable &lt;code&gt;justin&lt;/code&gt; with a value of our new &lt;code&gt;instance&lt;/code&gt; and call it on our &lt;code&gt;setter method&lt;/code&gt; &lt;code&gt;implicitly&lt;/code&gt; nested in our marco, &lt;code&gt;name=&lt;/code&gt;. This will allow us to officially initialize a &lt;code&gt;name attribute&lt;/code&gt; with a &lt;code&gt;"string" value&lt;/code&gt; within our the new &lt;code&gt;instance&lt;/code&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%2Fo4wwgarw8i1ylpn01fqt.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%2Fo4wwgarw8i1ylpn01fqt.jpeg" alt="Image description" width="614" height="133"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Last but not least it's time to &lt;em&gt;read&lt;/em&gt; to the world the value of the &lt;code&gt;name attribute&lt;/code&gt; within our new &lt;code&gt;instance&lt;/code&gt;! But how? &lt;strong&gt;Take the variable &lt;code&gt;justin&lt;/code&gt; with a value of our new &lt;code&gt;instance&lt;/code&gt; and call it on our &lt;code&gt;getter method&lt;/code&gt; implicitly nested in our &lt;code&gt;marco&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;&lt;/strong&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%2Fk620ffomjxr00fx6gqmv.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%2Fk620ffomjxr00fx6gqmv.jpeg" alt="Image description" width="578" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;center&gt;THE END OF THE WALK&lt;/center&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;center&gt;&lt;/center&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%2F7bpnkay1741r8k44jnde.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%2F7bpnkay1741r8k44jnde.jpeg" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We learned the role of a &lt;code&gt;class model&lt;/code&gt; and the impact it has in order to &lt;code&gt;instantiate&lt;/code&gt; an &lt;code&gt;instance&lt;/code&gt;. It also has the ability to to act as a blue print which can hold &lt;code&gt;instance methods&lt;/code&gt; that can be called on by an &lt;code&gt;instance&lt;/code&gt; of our &lt;code&gt;class&lt;/code&gt;. But what if we wanted our &lt;code&gt;instance&lt;/code&gt; to have &lt;code&gt;attributes&lt;/code&gt; to give the instance a volt packed with detailed data? We would have to imprint &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter methods&lt;/code&gt; within our &lt;code&gt;class&lt;/code&gt;. Because an &lt;code&gt;instance&lt;/code&gt; is only an object with an identifier number, it is our job to take advantage of different types of &lt;code&gt;instance methods&lt;/code&gt; if we want to set &lt;code&gt;attributes&lt;/code&gt;. To do so, we learned how to &lt;em&gt;write&lt;/em&gt; &lt;code&gt;explicit&lt;/code&gt; &lt;em&gt;setter&lt;/em&gt; and &lt;em&gt;getter&lt;/em&gt; methods. One method has the responsibility of &lt;em&gt;writing&lt;/em&gt; an &lt;code&gt;attribute&lt;/code&gt; and the other method has the responsibility of &lt;em&gt;reading&lt;/em&gt; the value of the &lt;code&gt;attribute&lt;/code&gt; to the world.&lt;/p&gt;

&lt;p&gt;With being more than a few ways to write out &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter methods&lt;/code&gt;, we learned how to take on &lt;code&gt;marcos&lt;/code&gt;. A &lt;code&gt;marco&lt;/code&gt; is an &lt;em&gt;&lt;code&gt;instance method&lt;/code&gt; that &lt;code&gt;implicitly&lt;/code&gt; represents our &lt;code&gt;setter&lt;/code&gt; and &lt;code&gt;getter methods&lt;/code&gt;.&lt;/em&gt; &lt;code&gt;Marcos&lt;/code&gt; allows the representation of both methods individually or in a lump sum. Both syntax of a &lt;code&gt;marco&lt;/code&gt; work under the hood exactly the same. However, writing an &lt;code&gt;attr_accessor&lt;/code&gt; is less time consuming than writing &lt;code&gt;attr_writer&lt;/code&gt; and &lt;code&gt;attr_reader&lt;/code&gt;. Keep in mind the coding world is complexed with strategy and self coding awareness. There will be times using a specific &lt;code&gt;marco&lt;/code&gt; syntax will come into play!&lt;/p&gt;

&lt;p&gt;Until next time coders! Happy learning and coding! ✌🏽&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Resources&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Ruby Classes and Objects&lt;/strong&gt; &lt;a href="https://www.tutorialspoint.com/ruby/ruby_classes.htm"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Ruby Setters and Getters&lt;/strong&gt; &lt;a href="https://www.geeksforgeeks.org/ruby-getters-and-setters-method/"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Ruby Setters and Getters Link Two&lt;/strong&gt; &lt;a href="https://www.geeksforgeeks.org/ruby-getters-and-setters-method/"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.  attr_accessor, attr_writer and attr_reader&lt;/strong&gt; &lt;a href="https://www.rubyguides.com/2018/11/attr_accessor/"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.  attr_accessor, attr_writer and attr_reader Link Two&lt;/strong&gt; &lt;a href="https://bootrails.com/blog/ruby-attr-accessor-attr-writer-attr-reader/"&gt;link&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Components and Props in React!</title>
      <dc:creator>JustinBass</dc:creator>
      <pubDate>Tue, 14 Feb 2023 03:37:14 +0000</pubDate>
      <link>https://dev.to/justinbass/components-and-props-in-react-foi</link>
      <guid>https://dev.to/justinbass/components-and-props-in-react-foi</guid>
      <description>&lt;center&gt;**&lt;h1&gt;What is a Component?&lt;/h1&gt;**&lt;/center&gt;




&lt;p&gt;&lt;strong&gt;Components&lt;/strong&gt; in React are templates for our code. When you think of the likes of Amazon and Facebook, we can see that there are many different areas of these applications. These areas are responsible for their own functionality. The bigger the application, the more complex it becomes to keep track of these functionalities. Using &lt;strong&gt;components&lt;/strong&gt; allows us to modularize functionality as well as presentation within our code. &lt;/p&gt;

&lt;center&gt;**&lt;h1&gt;Creating a Component&lt;/h1&gt;**&lt;/center&gt;




&lt;p&gt;The number one rule when creating a &lt;strong&gt;component&lt;/strong&gt; is to have it initialized at the front end with a capital letter. This is how we differentiate between a &lt;strong&gt;normal function&lt;/strong&gt; and a &lt;strong&gt;component&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fu6lsnjz81752rxtw9idi.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fu6lsnjz81752rxtw9idi.jpeg" alt="Image description" width="569" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the code snippet above we've created a component called &lt;strong&gt;App&lt;/strong&gt;. Within the body of our &lt;strong&gt;component&lt;/strong&gt; we have a return statement that holds some JSX (JavaScript XML). JSX allows us to write HTML directly inside of REACT. When rendered to the browser we will see &lt;strong&gt;'Hello, DEV Community'&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Focbz9qrj2t71a0ubwsnk.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Focbz9qrj2t71a0ubwsnk.jpeg" alt="Image description" width="752" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What if we said &lt;strong&gt;App&lt;/strong&gt; was our High-Order &lt;strong&gt;component&lt;/strong&gt;? Meaning, we simply just want to make &lt;strong&gt;App&lt;/strong&gt; responsible for only rendering children &lt;strong&gt;components&lt;/strong&gt; that hold their own functionality and JSX? Not only will this prevent cluttered code in comparison to only using a single &lt;strong&gt;component&lt;/strong&gt; to render all of the work, but it will help us keep track of different areas of our application that are responsible for their own functionalities and JSX.&lt;/p&gt;

&lt;center&gt;**&lt;h1&gt;How does this work?&lt;/h1&gt;**&lt;/center&gt;




&lt;p&gt;I know you're probably thinking what in the heck is this guy talking about?! Let's break this down:&lt;/p&gt;

&lt;center&gt;**Step 1:** Let's first remove our JSX elements from our return statement in our **App component**. We will keep our **div** element seeing that in **React** it is a must to have a **div** element if we plan on having more than one element in our JSX template. In our case, we will have more than one child component being rendered in our return statement of our **App component** (parent component) between our main **div** element:&lt;/center&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fo1rj3i1l2sz7vkcf7y2k.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fo1rj3i1l2sz7vkcf7y2k.jpeg" alt="Image description" width="405" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Next, we will create a separate &lt;strong&gt;component&lt;/strong&gt; called &lt;strong&gt;Header&lt;/strong&gt; in React where we want our &lt;strong&gt;h1&lt;/strong&gt; element &lt;strong&gt;'Hello, DEV Community!'&lt;/strong&gt; to live and later be imported into our &lt;strong&gt;App component&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fqzxqpjd6xyg54et0qrcp.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fqzxqpjd6xyg54et0qrcp.jpeg" alt="Image description" width="550" height="205"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fvggcjmae83civ90r3mtf.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fvggcjmae83civ90r3mtf.jpeg" alt="Image description" width="446" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F04fwvyo41p0eh1ezga9c.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F04fwvyo41p0eh1ezga9c.jpeg" alt="Image description" width="568" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Now that we have our &lt;strong&gt;child component (Header)&lt;/strong&gt; set up, we need to figure out a way to render the &lt;strong&gt;component&lt;/strong&gt; in its &lt;strong&gt;parent component (App)&lt;/strong&gt;.&lt;/p&gt;

&lt;center&gt;In order to make this possible we will have to export the **Header component** like so:&lt;/center&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Foudgd2kc8imszs5cdjn0.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Foudgd2kc8imszs5cdjn0.jpeg" alt="Image description" width="588" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; We're not done yet. If you look at the browser we still don't see &lt;strong&gt;'Hello, DEV Community!'&lt;/strong&gt; being rendered:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fi4s2v6j7mn3s8deuyo55.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fi4s2v6j7mn3s8deuyo55.jpeg" alt="Image description" width="605" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why is that? We not only need to export the &lt;strong&gt;Header component&lt;/strong&gt;, but also need to import the &lt;strong&gt;component&lt;/strong&gt; in its &lt;strong&gt;parent component (App)&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F0jw5qblqwexbshpxp2aa.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F0jw5qblqwexbshpxp2aa.jpeg" alt="Image description" width="466" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we check our browser again, we still don't see &lt;strong&gt;'Hello, DEV Community!'&lt;/strong&gt; What in the world is going on?!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; There's one last step we need to do before we can see &lt;strong&gt;'Hello, DEV Community!'&lt;/strong&gt; rendered to the browser. What do you think that is? &lt;/p&gt;

&lt;p&gt;Earlier I mentioned &lt;strong&gt;'We not only need to export the Header component, but we need to also import the component in its parent component (App)'&lt;/strong&gt;. Once imported, we can render the &lt;strong&gt;Header component&lt;/strong&gt; inside the return statement of our &lt;strong&gt;App component&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fj1m45f4wcw47w1e2b2vm.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fj1m45f4wcw47w1e2b2vm.jpeg" alt="Image description" width="464" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if we check our browser we will see &lt;strong&gt;'Hello, DEV Community!':&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ftp2i3g8hhzrassvtoa95.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ftp2i3g8hhzrassvtoa95.jpeg" alt="Image description" width="752" height="351"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;center&gt;**&lt;h1&gt;Conclusion On Components:&lt;/h1&gt;**&lt;/center&gt;




&lt;p&gt;Note that we can use a &lt;strong&gt;component&lt;/strong&gt; more than once! Whether it be in the &lt;strong&gt;App component&lt;/strong&gt; or another &lt;strong&gt;parent component&lt;/strong&gt; to the &lt;strong&gt;Header component&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's take a look at this example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F70xjnvvlbg6a1vrma44w.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F70xjnvvlbg6a1vrma44w.jpeg" alt="Image description" width="482" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that we are rendering the &lt;strong&gt;Header component&lt;/strong&gt; twice inside the return statement of the &lt;strong&gt;App component&lt;/strong&gt; after the &lt;strong&gt;Header component&lt;/strong&gt; is imported. What do you think will happen?&lt;/p&gt;

&lt;p&gt;We would see &lt;strong&gt;'Hello, DEV Community!'&lt;/strong&gt; rendered twice inside of the browser:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fe9s7plakf686lq2r0d2w.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fe9s7plakf686lq2r0d2w.jpeg" alt="Image description" width="669" height="467"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;The beauty of &lt;strong&gt;components&lt;/strong&gt; is it allows us coders to keep our code clean and organized. If we were to do all of our functionalities and JSX only in our &lt;strong&gt;App component&lt;/strong&gt;, sure, it could work when done correctly. However, if we took that route there would be a massive amount of functionalities and JSX in one &lt;strong&gt;component&lt;/strong&gt;. As coders, we don't want that to happen. Doing so will cause a clutter of unorganized code making it hard for other coders and yourself to keep track of the application as it expands. If we modularize our code into different &lt;strong&gt;components&lt;/strong&gt; we are able to break our functionalities and JSX into separate parts making it easier to control the entire application.&lt;/p&gt;

&lt;center&gt;**&lt;h1&gt;What are Props?&lt;/h1&gt;**&lt;/center&gt;




&lt;p&gt;Props go hand in hand with &lt;strong&gt;components&lt;/strong&gt;. &lt;strong&gt;Props&lt;/strong&gt; allow us to pass information or data down from a &lt;strong&gt;parent component&lt;/strong&gt; to a &lt;strong&gt;child component&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So how do we use &lt;strong&gt;props&lt;/strong&gt;? Let's go back to our &lt;strong&gt;App component&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fu5uwx1qn3sq19b8qwqj3.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fu5uwx1qn3sq19b8qwqj3.jpeg" alt="Image description" width="482" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Right now we are not establishing a &lt;strong&gt;prop&lt;/strong&gt; within the &lt;strong&gt;App component&lt;/strong&gt;. Let's say I wanted to pass information down to my first rendered &lt;strong&gt;Header component&lt;/strong&gt; within the &lt;strong&gt;App component&lt;/strong&gt; return statement where our JSX template lives. How would I go about doing this? Let's break this down:&lt;/p&gt;

&lt;center&gt;**Step 1:** First we would need to create a name for the prop and have its value be the information or data we want to pass down to our **child component (Header)**:&lt;/center&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fdldom7vcytp3opduk4fm.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fdldom7vcytp3opduk4fm.jpeg" alt="Image description" width="800" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Next we would need to de-structure the &lt;strong&gt;prop (about)&lt;/strong&gt; in the &lt;strong&gt;Header components&lt;/strong&gt; parameters using curly braces:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fgjwognoide8g5cbhtpj0.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fgjwognoide8g5cbhtpj0.jpeg" alt="Image description" width="586" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; If we wanted to create an &lt;strong&gt;h2&lt;/strong&gt; element in our &lt;strong&gt;Header components&lt;/strong&gt; JSX template and use the value of the &lt;strong&gt;prop (about)&lt;/strong&gt; to represent the &lt;strong&gt;innerText&lt;/strong&gt; of our &lt;strong&gt;h2&lt;/strong&gt; element, we can:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fwao49u4bhs2pb9uhso4h.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fwao49u4bhs2pb9uhso4h.jpeg" alt="Image description" width="572" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if we take a look at our browser we can see that our &lt;strong&gt;prop&lt;/strong&gt; passed down from the &lt;strong&gt;parent component (App)&lt;/strong&gt; was utilized in our &lt;strong&gt;child component of App (Header):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fkc31bfwfqhy9ifh8pxvf.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fkc31bfwfqhy9ifh8pxvf.jpeg" alt="Image description" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;As you can see, the second render of the &lt;strong&gt;Header component&lt;/strong&gt; was not affected because we did not assign it a &lt;strong&gt;prop&lt;/strong&gt; value like we did for the first rendered &lt;strong&gt;Header component&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We can prove that when a &lt;strong&gt;component&lt;/strong&gt; is re-used we can give that &lt;strong&gt;re-used component&lt;/strong&gt; its own &lt;strong&gt;prop&lt;/strong&gt; value without affecting the original &lt;strong&gt;component&lt;/strong&gt; first rendered. Let's add a &lt;strong&gt;prop&lt;/strong&gt; to the second rendered &lt;strong&gt;Header component&lt;/strong&gt; in the &lt;strong&gt;App component&lt;/strong&gt; with a new value:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fr7f9njwrfgs3nlrwet8c.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fr7f9njwrfgs3nlrwet8c.jpeg" alt="Image description" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Now that we have added a &lt;strong&gt;prop&lt;/strong&gt; to the second rendered &lt;strong&gt;Header component&lt;/strong&gt; with a new value, we can de-structure the &lt;strong&gt;prop (aboutTwo)&lt;/strong&gt; inside the parameters of the &lt;strong&gt;Header component&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F7678rsm0qtspv428gi3g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F7678rsm0qtspv428gi3g.jpeg" alt="Image description" width="565" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; If we wanted to create an &lt;strong&gt;h3&lt;/strong&gt; element in our &lt;strong&gt;Header components&lt;/strong&gt; JSX template and use the value of the &lt;strong&gt;prop (aboutTwo)&lt;/strong&gt; to represent the &lt;strong&gt;innerText&lt;/strong&gt; of our &lt;strong&gt;h3&lt;/strong&gt; element, we can:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F63iyd4kw5i51tkja4tgr.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F63iyd4kw5i51tkja4tgr.jpeg" alt="Image description" width="595" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's take another look at our browser. We can now see that our second &lt;strong&gt;prop&lt;/strong&gt; passed down from the &lt;strong&gt;parent component (App)&lt;/strong&gt; was utilized in our second rendered &lt;strong&gt;child component of App (Header)&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fk7ah97aek7gh61q1wpxw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fk7ah97aek7gh61q1wpxw.jpeg" alt="Image description" width="800" height="477"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;center&gt;**&lt;h1&gt;Conclusion on Props:&lt;/h1&gt;**&lt;/center&gt;




&lt;p&gt;As mentioned &lt;strong&gt;&lt;em&gt;props allow us to pass information or data down from a parent component to a child component&lt;/em&gt;&lt;/strong&gt;. This can come in handy when more than one component needs to share the same information or data from a &lt;strong&gt;parent component&lt;/strong&gt;.&lt;/p&gt;

&lt;center&gt;**Resources:**&lt;/center&gt;

&lt;center&gt;**1. Components &amp;amp; Props**[link](https://reactjs.org/docs/components-and-props.html)&lt;/center&gt;

</description>
      <category>ai</category>
      <category>security</category>
      <category>privacy</category>
    </item>
    <item>
      <title>THE WORLD OF ITERATION.</title>
      <dc:creator>JustinBass</dc:creator>
      <pubDate>Thu, 17 Nov 2022 08:18:36 +0000</pubDate>
      <link>https://dev.to/justinbass/the-world-of-iteration-42fp</link>
      <guid>https://dev.to/justinbass/the-world-of-iteration-42fp</guid>
      <description>&lt;p&gt;&lt;strong&gt;STRUGGLE.&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;- Make forceful or violent efforts to get free of restraint or constriction.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Being a beginner in the coding world is like being a reborn infant struggling to execute words with pronunciation. Even more so like being an infant struggling to open your eyes for the first time to take in the world's light. When it comes to iterating in JavaScript, it is key to know and understand the types of methods you can use with iteration. The goal here is to set yourself up for a smooth experience without Mr. Struggle Bus hovering over you. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ITERATION.&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;- A procedure in which repetition of a sequence of operations yields results successively closer to the desired result.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I, myself struggled to understand the types of methods used to iterate over arrays and array objects. "Keep moving through the curriculum and eventually you will understand these methods further down the road." Well, when I ended up down that road I still found myself a bit lost, confused, and frustrated. It was then that I realized I needed to go back, review, and have a full understanding of what was happening underneath the hood of all iteration methods. Why? Because reading and understanding are fundamental!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F2dkahgda8ufzmtdim1yh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F2dkahgda8ufzmtdim1yh.gif" alt="Image description" width="382" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;TYPES OF ITERATION METHODS&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A few iteration methods that stood out to me the most in JavaScript are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.map()&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.find()&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.reduce()&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.forEach()&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each of these methods has a unique execution-style within JavaScript. And as mentioned, it is essential to understand how they work so we know the right time and the right place to use them. &lt;a href="https://media2.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%2Ff78cookph6u5qubtypkp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ff78cookph6u5qubtypkp.gif" alt="Image description" width="225" height="168"&gt;&lt;/a&gt; In a perfect world, one method would work on every single array or array object. But let's be honest with ourselves. Perfection is insanity! We don't want to end up like Meryl Streep in 'Death Becomes Her' so focused on just one potion fixing all of our problems. We all witnessed how that turned out for her. If we thought only one of these methods would work with our coding we would never evolve as software engineers.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;What is the .map() method?&lt;/strong&gt;&lt;br&gt;
The &lt;strong&gt;.map()&lt;/strong&gt; method is used when we are looking for specific values matched with a specific key within an array object to create a new array of just those values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; &lt;br&gt;
Let's say we have an array object (list) of celebrities who offer Celebrity Cameos to fans. In the array object, we have each celebrities name, career, and cameo set price. Take a look at the snippet of code below, study it, and ask yourself "How can I get a list of all cameo prices for each celebrity involved to create a new array of just those prices?". &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F9fav5gg5z7asyxxbygqq.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F9fav5gg5z7asyxxbygqq.jpeg" alt="Image description" width="800" height="731"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you guessed we have to use the &lt;strong&gt;.map()&lt;/strong&gt; method. Bravo!👏🏽&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Where do we go from here?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There are two ways we can execute a new array of just the key-value pair "cameoPrices" as shown in the example above. the first syntax we can use within a &lt;strong&gt;.map()&lt;/strong&gt; method is an arrow function within the &lt;strong&gt;.map()&lt;/strong&gt; method. The second syntax we can use is an anonymous function assigned to a variable and call that function later using the &lt;strong&gt;.map()&lt;/strong&gt; method.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is an arrow function?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;An arrow function is a great way to make your code look clean and less cluttered. It does not need a literal &lt;strong&gt;"return"&lt;/strong&gt; typed. We don't need to use &lt;strong&gt;{}&lt;/strong&gt; (brackets) to create a function body. It is best practice to use arrow functions to keep your code modern.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is arrow function syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fa04iwgx0eaw2e2n1etor.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fa04iwgx0eaw2e2n1etor.jpeg" alt="Image description" width="412" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is an anonymous function?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;An anonymous function essentially does the same work as arrow functions. However, we do need to use &lt;strong&gt;{}&lt;/strong&gt; (brackets) to create the body of the function. The body of the function is where we tell or function what to do. We do have a literal &lt;strong&gt;"return"&lt;/strong&gt; typed within the body function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is anonymous function syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fkoupvegmtuzynob54vzt.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fkoupvegmtuzynob54vzt.jpeg" alt="Image description" width="404" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, using arrow function syntax allows us to shorten our code in comparison to using anonymous function syntax. With arrow functions we can get rid of the word &lt;strong&gt;" function"&lt;/strong&gt;, our brackets &lt;strong&gt;{}&lt;/strong&gt; that create the body of our function, and the word &lt;strong&gt;"return"&lt;/strong&gt;. This makes for cleaner code on a single line.&lt;/p&gt;

&lt;p&gt;In some cases, we can also get rid of the parentheses in our arrow function if the function has a single parameter. In the above example, we have two parameters happening in our arrow function. But what would it look like if we had one?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Take a look!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F9opculf96oe4eckjomt9.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F9opculf96oe4eckjomt9.jpeg" alt="Image description" width="344" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Putting the .map() method to use with arrow functions&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now that we can spot the differences in syntax between arrow functions and anonymous functions, let's finally put our knowledge to the test using both syntaxes to create a new array of the specific key-value pair we are looking for. In our case, we are looking for each celebrities &lt;strong&gt;"Cameo Price"&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Take another look at the array object of celebrityCameo:&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F8lx4pr7pzjch0rny8cuf.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F8lx4pr7pzjch0rny8cuf.jpeg" alt="Image description" width="800" height="731"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Creating a new array of Cameo prices using a single arrow function.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;STEP ONE:&lt;/strong&gt; &lt;br&gt;
We need to assign our .&lt;strong&gt;map()&lt;/strong&gt; method that holds our arrow function to a variable name. Make the variable name not only make sense to you but to your viewers (coworkers) who may have to go in and debug your code down the road. I'm going to assign our &lt;strong&gt;.map()&lt;/strong&gt; method to the variable name &lt;strong&gt;"prices"&lt;/strong&gt;. This is because we want to create an array of prices that represent each celebrity's cameo. This again will make sense to you plus your debugger team.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fx0t0ey6hzsd384btrt0y.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fx0t0ey6hzsd384btrt0y.jpeg" alt="Image description" width="554" height="69"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that in the example above we are chaining our array object variable name &lt;strong&gt;"celebrityCameo"&lt;/strong&gt; to our &lt;strong&gt;.map()&lt;/strong&gt; method. This allows our method to have access inside the array object where the keys and values live.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP TWO:&lt;/strong&gt; &lt;br&gt;
Next we need to figure out what exactly we need to put in between the parentheses of our &lt;strong&gt;.map()&lt;/strong&gt; method. We know from the information given earlier that it will be an arrow function with a return. We know a function has a parameter that will take in an argument. The question is, what do we name that parameter? The beauty of parameters is that we can name them whatever we want. &lt;strong&gt;MAKE IT MAKE SENSE TO YOU AND YOUR VIEWERS!&lt;/strong&gt; I'm going to call my parameter &lt;strong&gt;"price"&lt;/strong&gt; because we are looking for the price of the celebrity's cameo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F8cz1ga4ucdp4g05xzdi8.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F8cz1ga4ucdp4g05xzdi8.jpeg" alt="Image description" width="680" height="96"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP THREE:&lt;/strong&gt; &lt;br&gt;
Now that we have set up our parameter name that will take in an argument we want to set up our return. Our return comes after our &lt;strong&gt;=&amp;gt;&lt;/strong&gt;. Remember that in a regular function we define our return by physically typing &lt;strong&gt;"return"&lt;/strong&gt; in the body of our function. Because this is an arrow function we don't have to physically type &lt;strong&gt;return&lt;/strong&gt; after &lt;strong&gt;=&amp;gt;&lt;/strong&gt; in our function. Our arrow function will know that our line of code after &lt;strong&gt;=&amp;gt;&lt;/strong&gt; will automatically return something back to us.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F4csapbk2p9wwim42itjp.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F4csapbk2p9wwim42itjp.jpeg" alt="Image description" width="800" height="103"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice yet again that we are chaining within the parentheses of our &lt;strong&gt;.map&lt;/strong&gt; method. What exactly or we chaining and why? We are taking our function parameter &lt;strong&gt;"price"&lt;/strong&gt; and chaining it to our key name &lt;strong&gt;"cameoPrice"&lt;/strong&gt; within our celebrity objects in our array object. This allows our parameter &lt;strong&gt;"price"&lt;/strong&gt; to have access to the value of the key &lt;strong&gt;"cameoPrice"&lt;/strong&gt; which is the price of the celebrities cameo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP FOUR:&lt;/strong&gt; &lt;br&gt;
After we correctly set up our variable with a value of our &lt;strong&gt;.map()&lt;/strong&gt; method that calls our arrow function, it's time to check our work and guarantee that we have created a new array with just a list of each celebrities cameo price point. We can do this in two ways. We can &lt;strong&gt;console.log&lt;/strong&gt; &lt;strong&gt;"prices"&lt;/strong&gt; and have the new array appear in our browser console. Or we can also call the variable &lt;strong&gt;"prices"&lt;/strong&gt; in our browser's console and have the new array appear in the console of the browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using "console.log(prices)" in VSC:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fu9hlr3qx8t53r4v8c0ji.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fu9hlr3qx8t53r4v8c0ji.jpeg" alt="Image description" width="800" height="148"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The new array that should appear in the browser console using "console.log(prices)" in VSC:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F7gplg6n7rdnujyca17k7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F7gplg6n7rdnujyca17k7.jpeg" alt="Image description" width="524" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The new array that should appear in the browser console when calling the variable "prices" in the console of the browser:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3z7hqr9v0x9pl6q9wo2f.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3z7hqr9v0x9pl6q9wo2f.jpeg" alt="Image description" width="492" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Putting the .map() method to use with anonymous functions!&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;STEP ONE:&lt;/strong&gt;&lt;br&gt;
We need to create an anonymous function that is declared by a variable, a parameter that takes in an argument that's followed by &lt;strong&gt;{}&lt;/strong&gt; (brackets) to create the body of the function where we tell our function what to do. Remember to make the name of the variable declaration make sense. I'm going to name my variable &lt;strong&gt;"celebrityCameoPrices"&lt;/strong&gt; because I'm looking for the cameo price of each celebrity. I then will name my parameter &lt;strong&gt;"price"&lt;/strong&gt;. Why I'm I naming it &lt;strong&gt;"price"&lt;/strong&gt;? I think you get the point. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Famk5nm09b3ap2zbktgim.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Famk5nm09b3ap2zbktgim.jpeg" alt="Image description" width="740" height="146"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP TWO&lt;/strong&gt;&lt;br&gt;
We now need to figure out what I want my function to do. Do you remember where we tell our function what to do in an anonymous function? If you said between the brackets where the body of the function lives, great job! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fajzmal4sz4r09yj91zqj.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fajzmal4sz4r09yj91zqj.jpeg" alt="Image description" width="698" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hmmm, but we're missing something here. What could it be? Remember, only arrow functions don't need a &lt;strong&gt;"return"&lt;/strong&gt;. Because it's an arrow function, JavaScript automatically knows to return what we're asking the function to do. Let's tweak the above code a bit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F0jnoy14w3iaxzhflpnb5.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F0jnoy14w3iaxzhflpnb5.jpeg" alt="Image description" width="706" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our &lt;strong&gt;"return"&lt;/strong&gt; our function will execute what we're asking it to do when called. Notice we are chaining &lt;strong&gt;"price"&lt;/strong&gt; to the key &lt;strong&gt;"cameoPrice"&lt;/strong&gt; like we did with the arrow function syntax. This allows access to the value inside of the key &lt;strong&gt;cameoPrice&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Say if we didn't have a return within or function body? What do you think we would get in return when our function variable is called? &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Take a look!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fulhmxf2y6ik5svcuw4c9.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fulhmxf2y6ik5svcuw4c9.jpeg" alt="Image description" width="734" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WE WOULD GET UNDEFINED!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP THREE:&lt;/strong&gt; &lt;br&gt;
What can we do now that our function is built out? We need to set up our &lt;strong&gt;.map()&lt;/strong&gt; method to call our &lt;strong&gt;"function celebrityCameoPrice"&lt;/strong&gt;. We will take the same steps we did for the arrow function. Assign our &lt;strong&gt;.map()&lt;/strong&gt; method to a variable name. This time however our &lt;strong&gt;.map()&lt;/strong&gt; method will only have one thing in between the parentheses. That is our variable name &lt;strong&gt;"celebrityCameoPrices"&lt;/strong&gt; that is now equal to our function. I bet you were wondering where our function was going to be called.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fvpboohiwuwk8pne9dgb7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fvpboohiwuwk8pne9dgb7.jpeg" alt="Image description" width="800" height="77"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP FOUR:&lt;/strong&gt;&lt;br&gt;
As with arrow functions, there are to ways we can be sure our code is working. We can &lt;strong&gt;console.log&lt;/strong&gt; &lt;strong&gt;"cPrices"&lt;/strong&gt; and have the new array appear in our browser console. We can also call the variable &lt;strong&gt;"cPrices"&lt;/strong&gt; in our browser's console and have the new array appear in the console of the browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using "console.log(cPrices)" in VSC:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fyxbt2iz0vsu23dj0ecus.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fyxbt2iz0vsu23dj0ecus.jpeg" alt="Image description" width="800" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The new array that should appear in the browser console using "console.log(cPrices)" in VSC:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ftbomcx5y4gz78t4b51m5.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ftbomcx5y4gz78t4b51m5.jpeg" alt="Image description" width="490" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The new array that should appear in the browser console when calling the variable "cPrices" in the console of the browser:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fubmpq1gu8sgkjooxldq9.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fubmpq1gu8sgkjooxldq9.jpeg" alt="Image description" width="452" height="285"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;WE DID IT!&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F7j11i7zv009gfkhe3ap4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F7j11i7zv009gfkhe3ap4.gif" alt="Image description" width="447" height="251"&gt;&lt;/a&gt;&lt;br&gt;
We learned how to use the &lt;strong&gt;.map()&lt;/strong&gt; method to look for specific values matched with a specific key within an array object to create a new array of just those values. Not only did you learn to do it with one function syntax, but two function syntax! Round of applause ladies and gents! &lt;/p&gt;

&lt;p&gt;If you enjoyed this blog stay tuned for the next few blogs about other iteration methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.find()&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.reduce()&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.forEach()&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Until next time, happy coding coders! 👽&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Resources&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Arrow Function Expressions&lt;/strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Anonymous Functions&lt;/strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. .map() Method&lt;/strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>freelance</category>
      <category>career</category>
    </item>
  </channel>
</rss>
