<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Krystle Lee on Medium]]></title>
        <description><![CDATA[Stories by Krystle Lee on Medium]]></description>
        <link>https://medium.com/@l33.krys?source=rss-d0f74d161b23------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*JwEmj236EkcRdU6D</url>
            <title>Stories by Krystle Lee on Medium</title>
            <link>https://medium.com/@l33.krys?source=rss-d0f74d161b23------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 02:13:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@l33.krys/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Full-Stack E-Commerce: From Inception to Completion]]></title>
            <link>https://medium.com/@l33.krys/full-stack-e-commerce-from-inception-to-completion-ad5034ac67c9?source=rss-d0f74d161b23------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad5034ac67c9</guid>
            <dc:creator><![CDATA[Krystle Lee]]></dc:creator>
            <pubDate>Sun, 12 Nov 2023 07:19:12 GMT</pubDate>
            <atom:updated>2023-11-12T07:19:12.315Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2vRhl0vY4pr9ZhKd" /></figure><p>For my final project in Flatiron Software Engineering bootcamp, I built a fake e-commerce site. I thought this would be a fun project since I enjoy online shopping. Building an e-commerce site gave me the opportunity to focus more on building out the features and functionality of the site rather than create logic for a new app. I also thought this project would allow me to add more functionality over time as I continue my learning.</p><h4>Laying It All Out</h4><p>Before writing any code, I began to plan out my database tables and how they would connect to each other. I soon found out that e-commerce was a lot more complex than I thought. There are so many ways to set up your tables and their relationships. For this project, I kept it simple with only 5 tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/0*bMGd-JA7tSzL4CdJ" /></figure><h4>Creating Classes</h4><p>Now that I had a plan on how to lay out my data, I went to work on writing out my classes using Flask with SQLAlchemy. I ran into some issues with my classes when I tried to connect my ‘customers’ table with my ‘addresses’ table. The customers table had two foreign keys to the same addresses table. I only had experience with connecting tables with a foreign key in a bidirectional relationship so this had me stumped. Upon researching, I found that by removing the back_populates and specifying the foreign key in the relationship would be what I needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yJF9lDwxQDsVMkbk" /></figure><h4>Serializing with Marshmallow</h4><p>With all the tables ready, I set up my routes. To make things easier, I created full CRUD (create, read, update, delete) routes for all my tables. I prefer to do this so that I can make sure the relationships between the tables are working as expected. To serialize my data, I decided to use Flask Marshmallow. Marshmallow is an ORM/ODM/framework-agnostic library for converting complex data types, such as objects, to and from native Python data types. Flask Marshmallow is a thin integration layer for Flask and marshmallow that adds additional features to marshmallow and integrates with Flask SQLAlchemy. Although it seemed like I had to write out more text to use this library, it was visually a lot clearer to see what was being included in the response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EO0781beKsORAQr_" /></figure><p>There are some slight differences in how you would set up the response. With marshmallow, you don’t need to do a list comprehension on customers nor call .to_dict(). Instead, in the response you would use the customer schema created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YlDdF_EApWostA8W" /><figcaption>Using marshmallow</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vowYz4RpDcHBwbyt" /><figcaption>Using serialize rules</figcaption></figure><h4>Rendering Items</h4><p>Since the backend was set up for the most part, I moved to the front end to start building out some functionality. The first thing I wanted to tackle was rendering my items. I used redux toolkit query for this. I set up the store and created an itemsAPI that would do a fetchBaseQuery to my items endpoint. I was then able to use this data in my components to display the items.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VpM0E4ZegE_lVBLz" /></figure><h4>Sign Up and Login</h4><p>Next up was working with the customers data. I needed a way for customers to sign up and login. I set it up so that when a new customer was created, it would also set the session[‘customer_id’] to that new customer. This would eliminate the extra step for the customer to have to login right after creating an account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HSSV18sDA2Lm0ryI" /></figure><h4>Add to Cart</h4><p>Setting up the cart was probably the most challenging part of the project. I had to figure out a way to add items to the cart while also consolidating rows. If an item was added twice, it should only have one row and not create multiple rows. The customer should be able to update the quantity of their items all the while the total should reflect the changes. Inventory had to be checked before an order was submitted. If there wasn’t enough inventory, a response should be sent back to notify that there’s an error in their order. If there was enough inventory to fulfill the order it can move forward and be submitted. A new order should be created for their next order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hjkQ6MEEJ-aNp1Qz" /></figure><h4>Proceed to Payment</h4><p>To complete the shopping experience, I wanted to include a payment process. Rather than create my own form to collect payment, I decided to redirect to a Stripe-hosted payment page. Stripe is a payment service provider that accepts online payments. It was a lot easier to integrate than I thought it would be. Looking at the documentation, I basically had to create a route to my backend that would create a checkout session. I added some lines of code before it created the checkout sessions so that I could get the order total to include on the checkout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v9LiyK32CGnQ1sdZ" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/0*dfu0TlZjPRIG-qgn" /></figure><p>Creating a fake e-commerce definitely put to test all the skills I’ve learned during Flatiron’s Software Engineering bootcamp. Having to switch back and forth between Python and React while also incorporating new concepts felt uncomfortable at first but as I moved further in the project, I found my groove. I’m happy with the way the project turned out and hope to continue building out more features as I progress in my learning.</p><p>Resources</p><ul><li><a href="https://docs.sqlalchemy.org/en/20/orm/join_conditions.html#handling-multiple-join-paths">SQLAlchemy 2.0 Documentation</a></li><li><a href="https://marshmallow.readthedocs.io/en/stable/index.html">marshmallow: simplified object serialization - marshmallow 3.20.1 documentation</a></li><li><a href="https://flask-marshmallow.readthedocs.io/en/latest/">Flask-Marshmallow: Flask + marshmallow for beautiful APIs - Flask-Marshmallow 1.3.0 documentation</a></li><li><a href="https://www.nerdwallet.com/article/small-business/what-is-stripe">What Is Stripe, and How Does It Work to Accept Payments?</a></li><li><a href="https://stripe.com/docs/payments/accept-a-payment?platform=web&amp;ui=checkout#redirect-customers">Accept a payment</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad5034ac67c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[APIs: Which route will you take?]]></title>
            <link>https://medium.com/@l33.krys/apis-which-route-will-you-take-4d649194f6ce?source=rss-d0f74d161b23------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d649194f6ce</guid>
            <dc:creator><![CDATA[Krystle Lee]]></dc:creator>
            <pubDate>Sun, 22 Oct 2023 05:16:15 GMT</pubDate>
            <atom:updated>2023-10-22T05:16:15.536Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-GdcFarBgIfmGuASxLJRuw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@diegojimenez?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Diego Jimenez</a> on <a href="https://unsplash.com/photos/lone-road-going-to-mountains-A-NVHPka9Rk?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><p>In phase 4 of Flatiron Software Engineering bootcamp we learned how to build restful APIs using Flask and SQLAlchemy. We had dealt with data in JSON format back in Phase 2 but creating the routes for the data to travel on was something I had never done. Without these routes, you wouldn’t be able to send data from the back end to the front end. The reverse is also true since there would be no “route” for the data to travel back to the server. Building these routes might seem daunting at first but once you get the hang of it, it’s easy to create your basic CRUD (create, read, update, delete) routes and even get a little creative and build customized routes.</p><h4><strong>GET</strong></h4><p>Once you’ve built your model classes and have some data in your database, you’ll want to get access to this on the front end. The most basic route you want to create is a GET route to return all the entries in your model class. To illustrate, I’ll use my phase 4 group project as an example. We created a party planner app that had a model class called Party. It would be a good idea to be able to see a list of parties on the site so that you know what parties you have created. We’ll use the GET method and create a route to this data. With the help of some libraries from flask and flask_restful we can build our APIs with the Api class constructor and add in Resource subclasses.</p><p>Your code will look like this to create the route:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_p-ehPTo5GU4wgnw" /></figure><p>Entries in the Party table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EnZAsSISFulJc7SY" /></figure><p>With the server on, you can access the route using your browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/0*46qWOMD3qavJ5Yrd" /></figure><p>Using party data to create a visual on the front end:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m0r0UQdLClEBsMwJ" /></figure><p>Now that we’re able to get the list of parties onto our site, a user might also want to create more parties (POST), edit (PATCH), or delete (DELETE) these parties.</p><h4><strong>POST</strong></h4><p>To create a new party, we can add the POST method within our Parties class. You might be wondering, how do we enter the information to create a new party? If you have a front end, you can create a form to capture the inputs. Another way to create new entries is using an API platform like Postman or Insomnia or my favorite one is ThunderClient which you can use directly in VS Code. Once the inputs have been sent in a post request, the values will be used to create a new party entry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*759WbH895kTci7ZC" /></figure><h4><strong>GET by ID</strong></h4><p>Sometimes you don’t want to get all the data but are just interested in a particular entry. You can do this by referencing the ID. You’ll have to create a new class that will take in a parameter for the ID. This new class will utilize the get method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tey8Vz9yDP2mxnfd" /></figure><h4><strong>PATCH and DELETE by ID</strong></h4><p>Adding a patch and delete method within this class will make this full CRUD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hx0lENJi-Vys5it1dlBA-w.png" /><figcaption>PATCH Method</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7nMnlGJvAergp3Kd" /><figcaption>DELETE Method</figcaption></figure><h4><strong>Custom APIs</strong></h4><p>After building out these API routes, you may want to get creative and find out what other routes you can make to get other pieces of data that might be of interest. Setting up basic GET routes only gives you a list of row entries from the table but what if you wanted to do some aggregation methods.</p><p>Here’s an example of creating a class to get the total number of parties and guests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xlIf302WO2hySDdE" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/0*bcFuhsJIrxgNIgp6" /></figure><h4><strong>Route to Success</strong></h4><p>The server will include a response code along with the data back to the browser. In the case of the example code, the response code has been included in each method. If none are provided there are default HTTP response status codes. This can be useful when you want your front end to do certain actions based on the response received from the server. For example, if you are trying to input data in your form that is incorrect. The server will send an error message with a code. The front end can be set up to evaluate the response code and perform an action based on the response received.</p><p>Once you create full CRUD for a model, it can be easily duplicated across all other models in your app. This will leave more time to play around with the data and create your own custom routes. When you see that you’ve successfully created a new route it can get addicting to create more.</p><h4>Resources</h4><ul><li><a href="https://github.com/l33krys/party-planner">GitHub - l33krys/party-planner</a></li><li><a href="https://mannhowie.com/rest-api">REST APIs Explained - 4 Components</a></li><li><a href="https://flask-restful.readthedocs.io/en/latest/">Flask-RESTful - Flask-RESTful 0.3.10 documentation</a></li></ul><p><a href="https://flask-restful.readthedocs.io/en/latest/">https://flask-restful.readthedocs.io/en/latest/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d649194f6ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python CLI Pains: Navigation and Data Handling]]></title>
            <link>https://medium.com/@l33.krys/python-cli-pains-navigation-and-data-handling-f57a0b9c09e3?source=rss-d0f74d161b23------2</link>
            <guid isPermaLink="false">https://medium.com/p/f57a0b9c09e3</guid>
            <dc:creator><![CDATA[Krystle Lee]]></dc:creator>
            <pubDate>Sat, 30 Sep 2023 03:43:43 GMT</pubDate>
            <atom:updated>2023-10-06T15:40:55.914Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bwtVarzuSAXiu8ui.png" /></figure><p>Phase 3 in Flatiron Software Engineering bootcamp was about Python. I had some exposure to Python when I took some courses for Data Science. I was looking forward to seeing some familiar concepts and learning more about pandas but they were nowhere in sight. It was interesting to see how Python could be used for something other than Data Science. My learning in this phase mainly dealt with classes and object-relational mapping (ORM). Using these concepts we were tasked to create a command-line interface (CLI) project. Our group decided to create a fitness tracker with a User, Exercise and Log class. The most challenging part of the project for me was navigation and data handling. How do we create an app where the only user interaction comes from the keyboard?</p><h4><strong>If Statement</strong></h4><p>I was able to create the menu navigation utilizing if statements. To make this process more manageable, I started with a basic list of items I wanted the user to be able to do. The user should be able to create a user profile, create exercises and track their workouts at a minimum. Once I had that laid out, I started adding some conditionals with if statements. I decided to use number inputs as a way to make navigation easier. Less typing for the user is always better. Quicker to move around and less chance for accidental inputs. What I found interesting was that when you capture the user’s input from the command-line, it converts all text to strings. It wasn’t a big deal at this point in the project so by adding quotation marks around the numbers in my code, my if statement was checking for string “1” and not an integer of 1.</p><h4><strong>While True</strong></h4><p>At this point, the menu was set up to take inputs and run code based on the input. In the case of the project, the code would take you to a sub menu with another list of options. I wanted to keep the menu showing for the user as a reference point. Without the menu there, the user could get lost and forget where they were in the app. The “while True” statement helped with this task. While true, the section menu would continue to show for wherever you were in the app. Since there was no code to update this condition, the menu would stay in place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QT0eo8JbWeLwX2PY" /></figure><h4><strong>Try and Except</strong></h4><p>Data handling was the other part of the project that drove me crazy. Python has a builtin function to capture user input by using .input(&lt;prompt&gt;). When the user creates their profile, an exercise, or logs a workout the app needs to collect information. For regular text inputs, there is no problem but if we want to collect numbers for a user’s height or weight this presents some issues. Converting the response to an integer works if a number was given but in cases when the user makes a mistake, it throws an error and kicks you out of the program. To avoid this from happening, I put to use “try” and “except”. Try will “try” a block of code. If the code throws an error, the “except” will provide a way to handle the error. You can provide a descriptive message to the user to inform them why they got the error. Combining this with “while True” helped to run this block of code until I got an input that matched my requirements. By staying in this loop, the user could fix their mistake before moving on rather than finding out at the end that they gave incorrect information and start the process all over again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GpNNrq-xJcRYjke5" /></figure><p>Creating a seamless user experience with navigation and simple user inputs can make any app one would want to use. It wasn’t easy but going through the painful parts of building out menus and data handling will hopefully help me to become a better programmer. It’s great when coding comes naturally but the areas you struggle in force you to slow down and really dive into what’s in front of you to develop a better understanding.</p><h4><strong>Resources</strong></h4><p>https://www.geeksforgeeks.org/how-to-use-while-true-in-python/</p><p><a href="https://www.w3schools.com/python/python_try_except.asp">https://www.w3schools.com/python/python_try_except.asp</a></p><p><a href="https://www.pythonforbeginners.com/control-flow-2/when-to-use-try-catch-instead-of-if-else#:~:text=The%20if%2Delse%20block%20works,more%20than%20if%2Delse%20block">https://www.pythonforbeginners.com/control-flow-2/when-to-use-try-catch-instead-of-if-else#:~:text=The%20if%2Delse%20block%20works,more%20than%20if%2Delse%20block</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f57a0b9c09e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Reflection: Key Takeaways]]></title>
            <link>https://medium.com/@l33.krys/react-reflection-key-takeaways-8920bd3bc2e7?source=rss-d0f74d161b23------2</link>
            <guid isPermaLink="false">https://medium.com/p/8920bd3bc2e7</guid>
            <dc:creator><![CDATA[Krystle Lee]]></dc:creator>
            <pubDate>Sat, 09 Sep 2023 05:11:57 GMT</pubDate>
            <atom:updated>2023-09-09T05:11:57.839Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*5_W7O2jzUXq4zusa.png" /></figure><p>In the second phase of Flatiron Software Engineering bootcamp, we were introduced to React. React uses JavaScript but with some new concepts like components, props, and state. Since I heard good things about it, I was interested in seeing what all the hype was. In the beginning of learning React, I was having a hard time wrapping my mind around the new way of setting up my code and how this could actually be better. I was so used to explicitly writing what I want my code to do that I felt somewhat lost. It seemed like the code I was writing was redundant and seemed longer even though it felt like shorthand JavaScript. It wasn’t until project week where I started to realize and see the benefits of React.</p><h4><strong>Imperative JavaScript</strong></h4><p>In order to see the benefits of React, a quick recap of JavaScript is necessary. JavaScript is considered imperative programming. Coding in plain vanilla JavaScript is a lot more detailed. There’s an index.html file with your HTML framework and an index.js file that contains your JavaScript code that will get triggered with an event. You have to write a lot more to accomplish a task. Identify the HTML element on the DOM, attach an event listener and write some code that would do something.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L9pm1PGz_63n22g8" /></figure><h4><strong>Components are like Containers</strong></h4><p>On the other hand, React code is declarative and describes what needs to happen and not how it should happen. One reason React is different and better from JavaScript is the concept of functional components. Within your React components, everything you need to accomplish something is in one file. At the top, you have your list of imports. This is where you import React along with any other dependent files that are needed for your code. Below that is the functional component which starts with a capital letter and can help set it apart from a regular JavaScript function. This will return JSX (JavaScript XML) which looks a lot like HTML and will attach to the DOM. JSX can only return one parent element and will need to nest all other elements. At the bottom, you will export it so that other files can reference and use it. What’s nice about this is that you can see it all in one place. The layout of your HTML and what you want to happen. No need to check the DOM to find the element you want to attach an event listener to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aHAqWsF8wgr5aRUB" /></figure><h4><strong>Passing Information as Props</strong></h4><p>Components can stand alone by themselves or they could get passed properties (props) to connect with other components. Props can be objects, arrays or functions. It’s given a name and assigned with curly brackets.The receiving component will receive it in its parameters with curly brackets. Props can only be passed down to child components. Siblings can’t send props to each other. To better understand this I imagine my mom opening the lines of communication and sending me a message. I can only respond back using the same line. If I want to share this information with my brother, I can’t. I would need to have my mom share that with him. What’s nice about props is that it can send different information using the same prop names. An example of this is rendering the same component multiple times and passing the same props but each time I pass the props, it contains different information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TvCqENSRpPnPhZ47" /></figure><h4><strong>State: Set it and it won’t forget</strong></h4><p>State is another new concept that I learned about in React and can also be passed as a prop. In order to use state it has to be imported into your file with the useState hook. With state comes a setter function. State should be immutable and should use the setter function to update state indirectly. Because of the way props information flows downward, you will want to lift state to the component that is the common parent of the components that need access to this information. Thinking back to family, it would be like putting state with the grandparent if both my aunt and I need access to state. Putting state with my mom wouldn’t work since siblings can’t pass props to another sibling. State is unique in that it retains data between renders and when its state is set it will trigger a render. This is useful when we want to get the latest data from the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Az41AO_YkyaK73rf" /></figure><p>Learning React had its challenges in the beginning but I’ve come around to prefer this over vanilla JavaScript. It was easy to see the difference from my JavaScript project files versus React project files. For my group JavaScript project, having one index.js file got quite long and unorganized. React does require more thoughtful coding and planning so that components will get access to the data it needs. Separating functions into components makes it clear what it’s being used for and allows individuals to work on a piece of the project without much interference. With its modular structure and information handling, it is easier to collaborate with others and create more complex projects.</p><h4><strong>Resources</strong></h4><p><a href="https://www.educative.io/answers/what-is-importing-and-exporting-in-react-js">https://www.educative.io/answers/what-is-importing-and-exporting-in-react-js</a></p><p><a href="https://www.freecodecamp.org/news/beginners-guide-to-props-in-react/#:~:text=Props%20are%20used%20to%20store,interfaces%20across%20the%20component%20hierarchy">https://www.freecodecamp.org/news/beginners-guide-to-props-in-react/#:~:text=Props%20are%20used%20to%20store,interfaces%20across%20the%20component%20hierarchy</a>.</p><p><a href="https://blog.devgenius.io/whats-and-why-s-of-state-in-react-8208feb6912e">https://blog.devgenius.io/whats-and-why-s-of-state-in-react-8208feb6912e</a></p><p><a href="https://react.dev/learn/passing-props-to-a-component">https://react.dev/learn/passing-props-to-a-component</a></p><p><a href="https://react.dev/learn/writing-markup-with-jsx#jsx-putting-markup-into-javascript">https://react.dev/learn/writing-markup-with-jsx#jsx-putting-markup-into-javascript</a></p><p><a href="https://www.geeksforgeeks.org/reactjs-functional-components/">https://www.geeksforgeeks.org/reactjs-functional-components/</a></p><p><a href="https://medium.com/@myung.kim287/declarative-vs-imperative-251ce99c6c44">https://medium.com/@myung.kim287/declarative-vs-imperative-251ce99c6c44</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8920bd3bc2e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Scope and Hoisting: Why do they matter?]]></title>
            <link>https://medium.com/@l33.krys/javascript-scope-and-hoisting-why-do-they-matter-b843cf8e39ce?source=rss-d0f74d161b23------2</link>
            <guid isPermaLink="false">https://medium.com/p/b843cf8e39ce</guid>
            <dc:creator><![CDATA[Krystle Lee]]></dc:creator>
            <pubDate>Sat, 19 Aug 2023 02:14:55 GMT</pubDate>
            <atom:updated>2023-08-19T02:14:55.595Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*YUrfe_8iAuJyxhT4Mk5OyA.png" /></figure><p>Learning to write code has been a fun and at times a challenging experience. It can be a love-hate relationship. You love it when it works but when it doesn’t imposter syndrome starts creeping in. Now in my third week of Phase 1 at Flatiron Software Engineering bootcamp, I’ve learned a couple things that can make writing code a little bit easier to accomplish what I want. I learned about scope and hoisting in JavaScript. Keeping these two concepts in mind helps to keep things in perspective. I will go over at high-level why this can help beginners get better at coding.</p><h3>What is a variable?</h3><p>Before getting into scope, let’s define what a variable is. Variables are created to store data that can be accessed at a later time. They can be declared 4 ways: automatically and assigned using either var, let, or const. It is good practice to declare them before using them. Using var to declare variables is not recommended since it creates a global variable when you may not intend it to be. This leaves us with let and const. Variables created using let signals that the information may change whereas const variables are used to store data that will not change.</p><h3>Scope: block, function, global</h3><p>In JavaScript, there are three kinds of scope: block, function and global. When variables are created in the block scope, it is enclosed in curly brackets. It’s only accessible within that block statement when variables are created using let and const.</p><p>An example of block scope is creating a variable within an if statement. The variables created are not accessible outside of the function. In the example, when the variable block is created with let, it will console.log once within the function but once we call console.log(block) outside, it throws an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/0*-RF6VjF71PCtAvoX" /></figure><p>Functions are blocks of code that can be used for repeatable actions. It can shorten the number of lines of code in your script by creating a set of actions you can call on when needed. Variables created in function scope are only accessible within that function. It is said they have local scope. You can reference the variable anywhere within the function. Any reference to it outside the function will come back as not defined. You can declare the same variable in different functions and they will all have a different value.</p><p>With our example, the inner variable is accessible within the function. An update was made to the variable and now reflects this new value. It is successfully consoled within the function. Getting the value for “inner” outside the function throws an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_UgzN-hUUj5HhcNf" /></figure><p>Global variables are declared outside of functions and reside towards the top of your script. They can be accessed anywhere and anytime. It’s a double etched sword. Because of this they should be used sparingly as they could cause unexpected results. The variable could unknowingly be updated and assigned to data you didn’t want. On the other hand this is especially helpful when you want to keep track of a certain piece of data. The variable can be updated as it’s passed from function to function and be called on to see what its current value is.</p><p>As you can see from our previous examples, this variable has already traveled through a couple functions. It was originally declared at the top of the script and has since been passed in block and function scope. The global variable is no longer “I’m everywhere”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/0*RaIx76e9cz6nGpIq" /></figure><h3>Hoisting: JS doing some heavy lifting</h3><p>Understanding hoisting is another concept in JavaScript that makes writing code easier. Functions are essential for transforming and returning data for use in our applications. The way a function is written and where it’s placed in your script can determine whether or not it gets run. When a function is declared in our code, it can be accessed anywhere. If you declare a function at the top of your code, it can be called on after. Thanks to hoisting, the reverse is also true. It essentially reads the variables and functions before it’s called on. By declaring your function, it doesn’t matter the order in which it shows on your JavaScript file. The same can’t be said for when a function is assigned to a variable. This is where order matters. Hoisting does not apply in these cases. It has to be assigned before it’s called. Calling on a function before it has been assigned to a variable will not run and cause your code to have problems.</p><p>Our example shows how a function has been assigned to the variable “top” before it’s been invoked. This doesn’t give any errors. The variable “bottom” was assigned a function at the bottom of the script and throws an error since it comes after it was invoked. The function “anywhere” doesn’t have an issue when declared after it’s invoked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*32H9_KLCbfaNJggvp-bY6w.png" /></figure><p>Knowing what variables you have access to and the flow of your functions can give you more control in how you set up your code. It’s made me more thoughtful when writing my code. I’ve only scratched the surface on these topics but it’s already made an impact on how I write code more effectively.</p><h3>Resources</h3><ul><li><a href="https://www.w3schools.com/js/js_variables.asp#:~:text=Try%20it%20Yourself%20%C2%BB-,Note,code%20written%20for%20older%20browsers">JavaScript Variables</a></li><li><a href="https://www.w3schools.com/js/js_scope.asp">W3Schools.com</a></li><li><a href="https://www.geeksforgeeks.org/javascript-es2015-block-scoping/">JavaScript ES2015: Block Scoping - GeeksforGeeks</a></li><li><a href="https://testbook.com/interview/javascript-hoisting-interview-questions#:~:text=JavaScript%20hoisting%20is%20one%20of,scope%20before%20executing%20the%20code.">JavaScript Hoisting Interview Questions 2023 (Basic to Advanced)</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Glossary/Hoisting">Hoisting - MDN Web Docs Glossary: Definitions of Web-related terms | MDN</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b843cf8e39ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>