<?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 Léna Faure on Medium]]></title>
        <description><![CDATA[Stories by Léna Faure on Medium]]></description>
        <link>https://medium.com/@lenafaure?source=rss-d67581bfc14b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H92y4rbLkEONrqwzoqmQgA.png</url>
            <title>Stories by Léna Faure on Medium</title>
            <link>https://medium.com/@lenafaure?source=rss-d67581bfc14b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 08:25:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lenafaure/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[Why working on a side project is your best move as a developer]]></title>
            <link>https://medium.com/free-code-camp/why-working-on-a-side-project-is-your-best-move-as-a-developer-3b5b68035ac6?source=rss-d67581bfc14b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b5b68035ac6</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[life-lessons]]></category>
            <dc:creator><![CDATA[Léna Faure]]></dc:creator>
            <pubDate>Mon, 28 May 2018 21:15:09 GMT</pubDate>
            <atom:updated>2018-10-29T20:52:11.085Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YiBfCMk8jSnG_GMPwFIujA.jpeg" /><figcaption>Originally published on <a href="http://www.lenafaure.com/"><strong>lenafaure.com</strong></a></figcaption></figure><p><strong>Edit: the beta version of my side project </strong><a href="https://timeshake.io/"><strong>timeshake.io</strong></a><strong> — an online calendar builder — is live ! Feel free to create an account, test the app and give feedback :)</strong></p><p>As a developer, the moments when I learn the most are those when I am building things. This is true for the stuff I build on the job, but even more when I work on something I <strong>choose</strong> to work on, a side project that really excites me and that I do on my own time.</p><p>Coding a feature or a full product is usually a process of tackling problems one by one, some easier to solve than others.</p><p>The hardest problems, those seemingly insurmountable at first, that force me to go deeper into the workings of a technology, are the ones that make me learn things that stick with me forever afterwards.</p><p>This is why I firmly believe that <a href="https://hackernoon.com/the-best-way-to-learn-new-technologies-is-by-doing-heres-some-inspiration-6ca144216790">the best way to learn new technologies is by doing</a>. More than that, as explained in <a href="https://medium.freecodecamp.org/@wesharehoodies?source=post_header_lockup">Indrek Lasn’</a>s articles, <strong>we should strive to build useful things as a way to make progress.</strong></p><p>If, like me and many developers, you enjoy building stuff, working on something you are excited about is <a href="https://medium.com/swlh/the-closest-thing-we-have-to-a-real-life-superpower-97260da93cc7">one of the most glorious experiences you can have</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xzv2yE1U41x5qA9j_4M63w.jpeg" /><figcaption><a href="https://unsplash.com/">unsplash.com</a></figcaption></figure><p>We developers are extremely lucky. We get to use our creative energy to produce things that others can use, and to enjoy the pure act of applying our craft to get things done, while getting better at it in the process.</p><p>And when the things we create also bring value to other people, the rewards are tremendous.</p><h3>Benefits of working on a side project</h3><p>There are numerous benefits of working on a side project. Here are a few of my favorites:</p><h4><strong>Keeps you motivated</strong></h4><p>A side project you are excited about gets you going and fuels your creativity. It’s your thing, your baby, your sweat and tears. With patience and work, you might even end up bringing a lot of value to its users and transform it into a business.</p><blockquote>“You have to do in order to learn. You have to try stuff, break stuff, regret you ever tried, overcome your laziness and get s**it done. ” - <a href="https://medium.com/u/af216b9d2c56">André Pena</a></blockquote><h4><strong>Drives you to learn new technologies faster and in-depth</strong></h4><p>When you are trying to make things work, you are learning far more in-depth than when just reading, watching, or coding along. Getting your hands dirty and treating the technology as a means to get where you want to be is the most effective way go from theory to actionable knowledge.</p><h4><strong>Opens up new opportunities</strong></h4><p>Having a side project and a particular interest for the technology you are using is something that makes you stand out, technically and as a person.</p><blockquote><strong><em>“Side projects can be immensely rewarding to talk about. They demonstrate a lot about how you work. ” — </em></strong><a href="https://medium.com/u/e184f9feff12"><strong><em>Tanner Christensen</em></strong></a></blockquote><p><a href="https://medium.freecodecamp.org/how-to-talk-about-your-side-projects-18b96f192817">This article</a> explains in detail how working on and talking about your side project can have a great impact on your career, even as a beginner and/or self-taught developer.</p><h4><strong>Improves your other skills</strong></h4><p>It helps you get better at other important skills: product design, UX/UI, marketing, and so on.</p><p>In your professional life, you don’t often get to work on a project from end-to-end. But with your side project, you are responsible for conceiving and designing the product, developing it, deploying it and marketing it. The responsibility of finding a way to learn enough to get to the results you want falls upon you.</p><h3><strong>How to choose your side project</strong></h3><p>The side project you choose can tremendously boost your creativity and growth, when you find your own sweet spot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P61U5vZAhsRJ-y-UVsTMjg.png" /><figcaption>The side project sweet spot</figcaption></figure><p>Below, I’ll be discussing how you can benefit the most while working at various stages of your side project.</p><h4><strong>The Fear of Shipping</strong></h4><p>The <a href="http://sethgodin.typepad.com/seths_blog/2010/06/fear-of-shipping.html">fear of shipping</a>, procrastination, and resistance have been heavily documented. They rank among the main reasons why a great amount of projects are never born and end up in the graveyard of abandoned projects. This means that <strong>the mere fact of finishing a project and bringing it out to users is already setting you apart</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*ysxAnMU86E9kj1Ny856EtA.jpeg" /></figure><p>However, since there is nothing important at stake, you can keep the pressure to a minimum. A side project is all about succeeding slowly, at your own pace, on your own terms.</p><p>Unlike in the workplace environment where failure has real-life consequences (downsizing, losing clients), the side project space is somewhere you can experiment, define your own measure of success, fail without risking anybody’s career or income, and have fun in the process.</p><h4>Taking it easy</h4><p><a href="https://medium.com/u/7ee29b787e9">Tobias van Schneider</a> said that side projects should be silly or trivial:</p><blockquote>“The only way a side project will work is if people give themselves permission to think simple, to change their minds, to fail - basically, to not take them too seriously.</blockquote><blockquote>When you treat something like it’s stupid, you have fun with it, you don’t put too much structure around it. You can enjoy different types of success.”</blockquote><p>You should treat your side projects as experiments and not let crippling questions and doubts kill the project before it becomes something. In other words:</p><blockquote><em>“My first piece of advice is to just f*****g do it.” - Tobias Van Schneider</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8s-GnxQPCyWNVc2WJyB5g.jpeg" /><figcaption><a href="https://unsplash.com/">unsplash.com</a></figcaption></figure><p>This is the place where you can fail without consequences and have as many shots as you want.</p><p>It is also the place where you can make tangible and measurable progress towards a goal that excites you. This will keep energizing you, and make you happier too.</p><h4>Finding the idea</h4><p>How can you find ideas for side projects?</p><ul><li><strong>Scratch your own itch: </strong>If you keep stumbling upon something that makes you say “why doesn’t this exist yet ?” or “I can do this much better”, it’s time to do a little research and go for it if the need isn’t met yet.</li><li><strong>That idea that keeps nagging you: </strong>You’ve been thinking about it for months or years. It keeps coming back and begs you to help it make its way into the world. Whether it’s transforming a feature from an app you love into a product, or cloning an existing product for a different purpose, if you feel the drive to make it, this is a good sign you have to get started.</li><li><strong>Execute ideas provided by others: </strong>Here are two articles that are full of ideas that you can consider, <a href="https://blog.producthunt.com/how-to-come-up-with-side-project-ideas-4a2c8049deba">How to come up with side project ideas </a>by <a href="https://medium.com/u/c2146664c8e4">Ryan Hoover</a> (Product Hunt founder) and <a href="https://hackernoon.com/a-quick-guide-to-help-you-picking-up-the-best-side-project-to-work-next-30e284e2b2f7">A quick guide to help you picking up the best side project to work next </a>by <a href="https://medium.com/u/af216b9d2c56">André Pena</a></li></ul><h4>The WOW effect</h4><p>While shipping a prototype that works well should be your main objective, <strong>the goal is also to delight the user of the product.</strong> Remember, you only get one chance to make a good first impression.</p><p><a href="https://medium.com/u/fffaa52a0aa3">Wayne Chang</a> has introduced the notion of MLP - Most Lovable Product - a prototype that provides a great experience for your first users.</p><blockquote><em>“An MLP is a product that is so intuitive, so satisfying to use, that your customer base can’t help but tell someone else about their experience.” - Wayne Chang</em></blockquote><p>Even with the minimal features, building a beautiful prototype can make you stand out and place you in <a href="https://blog.usejournal.com/want-to-build-an-incredible-product-strive-for-the-delta-of-wow-f184b716af18">the delta of wow</a>.</p><h3>Going in-depth with the technology</h3><p>I am picking up right where I left with my <a href="https://hackernoon.com/a-120-days-plan-to-become-a-better-developer-120daysbetterdev-4c3bbbdf31ee">plan to become a better dev </a>. I had to pause it for 6 months while <a href="https://medium.freecodecamp.org/the-developers-workflow-in-practice-how-we-built-our-mvp-in-30-days-c60d804695a8">building a startup for the City of Paris</a>.</p><p>Time for me now to dive into React. It’s never too late, right? 😉 It’s something I’ve wanted to do for a long time and never got to tackle properly.</p><p>I get really bored when trying to learn something new, and the default tutorial app is another blog or to-do-list that will end up in a graveyard of folders in my computer. Instead, I could use the time to create something meaningful.</p><p>Working on a side project helps me embrace the technology as I use it as a means to an end, transforming the idea I have into a tangible version of the product, a version that I am satisfied with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N0iQIcBVKASqZeSWz-GRbQ.jpeg" /><figcaption><a href="https://unsplash.com/">unsplash.com</a></figcaption></figure><h3>Documenting the process</h3><p>If you like to write, documenting your journey in itself can be a very rewarding exercise, too.</p><p>I find writing articles is a great way to log your progress, clarify your ideas, and allow you to see how you’ve improved. Journaling helps retain concepts and clear your head at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Syh8sGG-jiCShR1SlIhjig.jpeg" /><figcaption><a href="https://unsplash.com/">unsplash.com</a></figcaption></figure><h3>Go for it</h3><p>Having a side project that excites you will keep you motivated and you may find yourself carving out more and more chunks of time to achieve your goals in the process.</p><p><strong>Stick to one project and get it done</strong>, while learning a new technology along the way. Start small and succeed slowly. Whatever the outcome, you will have improved many of your skills and will feel the pride of having created something important.</p><p>— Léna Faure</p><h4>Thanks for reading, I hope you enjoyed this article. <a href="https://twitter.com/lenafaure">Say Hello on Twitter</a> or check out <a href="http://lenafaure.com/">my website</a>.</h4><p><em>Originally published at </em><a href="http://lenafaure.com/"><em>lenafaure.com</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b5b68035ac6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/why-working-on-a-side-project-is-your-best-move-as-a-developer-3b5b68035ac6">Why working on a side project is your best move as a developer</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The developer’s workflow in practice — how we built our MVP in 30 days]]></title>
            <link>https://medium.com/free-code-camp/the-developers-workflow-in-practice-how-we-built-our-mvp-in-30-days-c60d804695a8?source=rss-d67581bfc14b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c60d804695a8</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Léna Faure]]></dc:creator>
            <pubDate>Tue, 24 Oct 2017 21:05:32 GMT</pubDate>
            <atom:updated>2018-05-31T00:20:35.709Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oYtXYYF7F0cBuv2SWm78xA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/zPfn8ap8hTY?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Michał Grosicki</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>As a web developer, I often get to start projects from scratch and make decisions for a bunch of elements, from the technical stack to the final look &amp; feel of the app.</p><p>Especially when the stakes behind a project are high, this process can be overwhelming.</p><p>I want to share our experience of one month into the City of Paris Startups Program, and the steps our team took to achieve a first operating version of the app.</p><p>Some context first: <a href="http://alloanim.futur.paris/">AlloAnim</a> is a web app designed to help the City of Paris find available after-school staff instantly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vOTtrNbhxh2QW8lnp7yLWA.png" /><figcaption>Our current Homepage for the first Sprint — Inspired from AirBnb while working on a new UI — Credit Sophie Robichon / Mairie de Paris</figcaption></figure><p>The goal is to have after-school employees create and update their profile and availabilities as often as possible. This will allow the City of Paris to have direct access to a real-time updated database of available staff.</p><p>Our team is made of two people. One is Product Owner, Christian Bockarie. Christian was the person who identified the pain-point while working as a City of Paris school staff.</p><p>The other is a developer (yours truly), responsible for building the full-stack app within a 5 months period.</p><p>Our headquarters are at the open innovation community lab <a href="https://medium.com/u/80f73c80f26f">La Paillasse</a>. We work alongside the Startup <em>ViteUnLieu</em>, that helps organizations easily find conference rooms in Paris, with <a href="https://medium.com/u/711ccb98d56f">Jean Karinthi</a> as Product Owner and <a href="https://medium.com/u/f2c94c63e0f3">Christophe Robillard</a> as Lead Developer.</p><p>The stack we chose is Ruby on Rails for the back end and ‘vanilla’ (plain, no frameworks) JavaScript on the front end.</p><p>We want to integrate React as soon as possible, but for the prototyping phase we are sticking with good old JavaScript.</p><p>So how did we create a working product from scratch in one month? Here are the main steps we took to ship this first version successfully.</p><h3>1. Embrace the Agile Spirit</h3><p>We worked with a coach for two days to learn the basics of <a href="https://en.wikipedia.org/wiki/Agile_software_development">Agile development</a>.</p><p>The main take-away of Agile is that you have to work in very close collaboration with your final users. The goal is to iterate over every version of your app based on the feedback they provide.</p><p>This way you are less likely to build something that people don’t need, don’t like, or don’t know how to use.</p><h3>2. Quickly meet with users in real-life</h3><p>Christian managed to quickly get us a decisive meeting with the head of after-school staff in an elementary school.</p><p>We engaged in a meaningful conversation about how she currently handled her staffing problem. We learned what functionality she would absolutely need to have in our upcoming web tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KGtwidYUm7DQ1OxN_9mIzA.jpeg" /><figcaption>Credit Sophie Robichon / Mairie de Paris</figcaption></figure><p>The pain-point and need for our product proved to be definitely real. This was enough to get us started on a Minimum Viable Product (MVP). This is a product version with the necessary functionalities to be the first usable version of our product.</p><h3>3. Write User Stories</h3><p>User stories are a way for a non-technical Product Owner and a Developer to perfectly understand each other on what needs to happen for the app to fill its purpose.</p><p>They are written on the model: “As a &lt; type of user &gt;, I can &lt; some goal &gt; (so that &lt; some reason &gt;).”</p><p>So an example of one of our simple user stories was: “As a member of after-school staff, I can create a profile with my personal information”.</p><p>User stories fit together to form a Story Map, which is the global visual plan for building the app over time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*B7p8epBm1iEI8gXx." /></figure><p>The development cycle of the product is then sliced into sprints.</p><p>Each sprint contains a given number of user stories that will be coded into functionalities.</p><p>Our first sprint typically contains all the user stories that are needed for a usable Minimum Viable Product.</p><p>The Story Map and the content of the sprints are free to change at each iteration of the product. This usually coincides with a feedback session with users.</p><p>As users give feedback on the developed functionalities, the User Stories evolve and adapt to match the actual use of the app.</p><h3>4. Set up an Agile workflow</h3><p>I was lucky enough to work alongside the other startup’s talented developer <a href="https://medium.com/u/f2c94c63e0f3">Christophe Robillard</a>, who gained an impressive experience with Agile workflows and developer productivity from his previous experience in <a href="https://beta.gouv.fr/">Government Startups Program</a>.</p><h4>Daily Stand-Up Meetings</h4><p>Taken from the Scrum methodology, the daily stand-up is a standing meeting held on each day of a sprint. We talk to each other every beginning of the day for 5–15 minutes. We stand if we are physically together, or talk on the phone if we work remotely.</p><p>It helps set the context for the coming day’s work and commit to the tasks that have to be tackled next.</p><h4>Dev Backlog</h4><p>The sprint backlog gets visible by putting it on a<strong> </strong>task board, where each row on the board is a user story. Smaller, individual tasks are written on ‘cards’.</p><p>Team members update the task board continuously throughout the sprint by writing new cards or moving the cards. For example, a card could be moved from column “To do”<em> </em>to column “Doing”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*GvC5snIP_0CHeDkT." /><figcaption>Our task board for the first sprint</figcaption></figure><p>You can easily recreate this task board on the <a href="https://about.gitlab.com/features/issueboard/">Gitlab issue board</a> or on <a href="https://waffle.io/">Waffle.io</a> for a digital alternative.</p><h4>Bi-weekly meetings between Startups</h4><p>To make the meeting efficient and to-the-point, the strategy Christophe shared with us is the following:</p><ul><li>Set a maximum time for the meeting (30 minutes to 1 hour)</li><li>Write a sticky note for each subject that will be discussed and talk about only one sticky note subject at a time</li><li>Set a 5 minute timer for each sticky note discussion<br>If the discussion exceeds 5 minutes, decide between the team if it is worth resetting the timer for an additional 5 minutes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B5AxgQYSFi5FsSxDQwCUvA.jpeg" /><figcaption>Christophe provided us with some timeless knowledge on Agile, Lean Startup and Clean Code</figcaption></figure><h3>5. Get inspiration from well-designed websites and share a moodboard</h3><p>This is one of my favorite parts at the beginning of a project — seeking inspiration for UX and UI from other web apps, some of which I use very often.</p><p>I am always amazed at the creativity and cleverness of the teams behind some of the tools I use. For example, I was inspired by the onboarding process of <a href="https://hired.com/signup?utm_source=breaz&amp;utm_medium=referral">breaz.io</a>. I also admired the way <a href="https://www.drivy.com/">drivy.com</a> allows users to select a bunch of cars first, then send one message to every owner once the selection is made.</p><p>Here, I’ll present some of the tools that usually help me get started and visualize the app’s interfaces.</p><h4>Dribbble</h4><p>The search functionality on <a href="https://dribbble.com/">Dribbble</a> lets you pick the creative brain of great designers who showcase their work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6_-A_4N6yX5906d1BbLv0w.png" /></figure><h4>Moodboard</h4><p><a href="http://www.gomoodboard.com/">Moodboard</a> lets you collect, share and comment on designs with your team. This lets everyone get a taste of the inspiration for the website’s interface:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LpvHYk-wlawKxZee81ahLQ.png" /></figure><h4>Adobe Color</h4><p><a href="https://color.adobe.com/">Adobe Color</a> is the perfect source of inspiration for harmonious palettes. The ‘Explore’ feature lets you browse thousands of inspiring color themes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QAUkKlRc8iSJSVWfjQv4Lg.png" /></figure><h3>6. Create the first Rails version of the App</h3><p>We set up our models and database with Ruby on Rails and SQLite. We used the ‘Devise’ gem for the authentication system.</p><p>I usually develop the front end and back end at the same time. This means I try to work on the design and responsiveness of each functionality as soon as it is born.</p><p>This never fails to produce some kind of ‘wow!’ effect when presenting the first demos. This first impression can be a decisive factor when users are adopting a product.</p><p>Some developers prefer to focus on the back end first. Once they get everything in working order, they go back over it for cosmetics further along. However, I find it easier to work on both simultaneously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9dlrcKmkImRLApKt." /></figure><p>In our app, the main object is the user. We have quite a road ahead of us to refine the onboarding system and find incentives for the user to return to the app often.</p><p>For now, the sign up process is basic and simply has the key information for the MVP to work.</p><p>Below are some screenshots of the MVP in action!</p><p><strong>Signing up:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xJX4CoOwV62CIKSHZMKGeA.gif" /><figcaption>Signing Up</figcaption></figure><p><strong>Looking for staff:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3xw4lw0G-WQbJzbzahZ6cw.gif" /><figcaption>Looking for available staff</figcaption></figure><p>The app requires a weekly calendar for the after-school staff to fill in their available time slots. However, I couldn’t find a Rails gem or JavaScript plugin that matched the particular requirements of the MVP.</p><p>So I set out to build a full Javascript weekly availability scheduler, and then integrate it in the Rails app. <a href="https://github.com/lenafaure/javascript-weekly-scheduler">You can find the JavaScript code here if you are interested</a>.</p><p><strong>Version 0 (Display weeks):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*jnA1RfrKBBXR9nb7." /></figure><p><strong>Version 1 (Add specific time-slots and responsive behavior):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*VJzZki_YqMw6J-Q1." /></figure><p><strong>Version 2 (Integrate in the Rails App — Profile page):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V0srF2EvciBWjQPdvH14eQ.png" /></figure><h3>7. Deploy the Live App</h3><p>The final step is to make the app live. I found <a href="https://www.heroku.com/"><strong>Heroku</strong></a><strong> </strong>made hosting it a breeze. Deployment is free, and directions are very simple and available directly on the platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5bUSm3xfd7nFNU-KyJPItw.png" /><figcaption>Heroku deployment instructions</figcaption></figure><h3>8. Iterate</h3><p>Finally, it is time to meet the users again, and present them the work you have done during the sprint.</p><p>We usually have 3-week sprints. This gives us time to actually code enough functionalities to have something of substance to discuss. It also lets our club of users breathe between meetings.</p><p>During the meeting, we listen to the users’ feedback and discuss the app’s functionalities with them.</p><p>Then, we go back to the task board to plan the next sprint… Until next time!</p><h3>Conclusion</h3><p>Sticky notes are life. Nothing good in the world would happen without them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*VzopnLtVd7gpi1uKnR_6Ag.jpeg" /></figure><p>That’s it for now! We are well into our second sprint and moving sticky notes with stupendous agility.</p><p>Any tools you use for your own process and would care to share with us are most welcome!</p><p><strong>Edit: </strong><a href="http://alloanim.futur.paris/">AlloAnim</a> prototype has successfully launched and is now being tested and used daily by the City of Paris staff.</p><p>You can find the <a href="https://gitlab.com/startups-ville-paris/animexpress">Open Source Code here</a>, and a full demo of the app below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fs0B95jJ1AFA%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Ds0B95jJ1AFA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fs0B95jJ1AFA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b2f167bcf000735ce748a1ecf1abc94/href">https://medium.com/media/7b2f167bcf000735ce748a1ecf1abc94/href</a></iframe><p><em>The </em><a href="https://twitter.com/hashtag/startupdeville?src=hash"><em>#</em><strong><em>startupdeville</em></strong></a><em> program is a City of Paris initiative, powered by public agents who have identified a clear pain point while working on the field.</em></p><p><em>After a selection process and a one-month acceleration, a two-person team (Product Owner + Developer) builds a web app to validate the need for this new service and its adoption by the target users.</em></p><p>If you enjoyed this piece, please show your love and clap so others can find it! Feel free to<a href="https://twitter.com/lenafaure"> follow me on Twitter</a>, as well as the <a href="https://twitter.com/hashtag/startupdeville?src=hash">#startupdeville</a> team members, <a href="https://twitter.com/BockarieChrist">Christian Bockarie</a>, <a href="https://twitter.com/JeanKarinthi">Jean Karinthi</a> and <a href="https://twitter.com/krichtof">Christophe Robillard</a></p><p>— Léna Faure</p><figure><a href="http://eepurl.com/dvio9L"><img alt="" src="https://cdn-images-1.medium.com/max/690/1*td_Zl-oX7vl2kIsoldqcLA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c60d804695a8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/the-developers-workflow-in-practice-how-we-built-our-mvp-in-30-days-c60d804695a8">The developer’s workflow in practice — how we built our MVP in 30 days</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A 120 Days Plan to Become a Better Developer #120DaysBetterDev]]></title>
            <link>https://medium.com/hackernoon/a-120-days-plan-to-become-a-better-developer-120daysbetterdev-4c3bbbdf31ee?source=rss-d67581bfc14b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c3bbbdf31ee</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Léna Faure]]></dc:creator>
            <pubDate>Sat, 05 Aug 2017 11:00:33 GMT</pubDate>
            <atom:updated>2019-05-15T12:00:53.687Z</atom:updated>
            <content:encoded><![CDATA[<h4>My Intensive Program to Level Up and Become an better Front-End Engineer</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d5zrWm8PdQjZH6mSRlRebA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/0RWzJ17SKEs?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Arnold Exconde</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I have been coding professionally as a full-stack developer for more than 3 years now and I particularly enjoy working on the front end. I am a bootcamp grad and self-taught developer, and while I learn a lot on the job on a daily basis, I have always had this urge to take the time to fully grasp the deep fundamentals of <a href="https://hackernoon.com/tagged/javascript">JavaScript</a> and <a href="https://hackernoon.com/tagged/programming">programming</a>, and to become a stronger developer.</p><p>Since I made an intensive plan for myself to level up and ace technical coding interviews, I decided to share it with you. Sometimes you just need to see the plan unfold to get started, so I’ll be happy if it can be of use to anyone.</p><p>I needed a program that would really <strong>get me ready for code interviews</strong>, that I could follow <strong>while working a full-time job</strong>, and <strong>not very expensive</strong>.</p><p>It was important to me that the program be intensive: I find that it’s easier to build and keep momentum in short bursts of massive action than to dabble for too long. I am more of a sprinter, but of course if you are of the marathonian type, you can easily spread this program over a longer period of time to fit your learning style.</p><p>I also purposefully chose several overlapping resources for each course: learning from a variety of medias (text, video) and being exposed to different ways of presenting a concept helps grab the content a lot better, not to mention the demonstrated benefits of repetition.</p><p>I have spent a lot of time researching, reading, looking for the best resources I could to build my own tailored curriculum (thanks for the inspiration <a href="https://frontendmasters.com/books/front-end-handbook/2017/">FrontEndMasters</a>, <a href="http://javascriptissexy.com/">JavaScriptisSexy</a> and <a href="https://medium.com/u/5c707271e2b5">Nick Ciubotariu</a> in this <a href="https://medium.com/@nickciubotariu/ace-the-coding-interview-every-time-d169ce1fd3fc">article</a>), and this is the result: <strong>a 4-month (very) intensive front-end engineering training, with a selection of excellent resources that cost less than 500€ </strong>combined. (It can cost much less if you choose alternative free resources of your choice of course).</p><p>Note that you should be comfortable with front-end development basics to hop on; Git, HTML, CSS, the DOM and JavaScript indispensable concepts (scope, this, closures, etc) are not part of this learning path. Tons of free good resources can help you quickly learn the beginner parts of the front end before taking on this program.</p><h3><strong>THE PROGRAM (120 days)</strong></h3><p>I am planning to work a minimum of 3 hours a day, with <strong>one mandatory coding exercise</strong> every day at the beginning of each session, that I will push on Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Mw2Z4UioyXsHSyCu." /></figure><blockquote><a href="https://docs.google.com/spreadsheets/d/1G9nXdOueyypkMfXd3TR8wNQZe5SVdULRu3mEtJ-Dq_I/edit?usp=sharing">You can find the Google Sheet with the planning + resources here.</a></blockquote><h3><strong>RESOURCES</strong></h3><p>Here is the list of the resources I will use along the program:</p><h4><strong>Books</strong></h4><p><a href="https://www.amazon.fr/Beginning-JavaScript-Jeremy-McPeak-ebook/dp/B00TTY96DA/ref=sr_1_1?s=digital-text&amp;ie=UTF8&amp;qid=1501598282&amp;sr=1-1&amp;keywords=beginning+javascript">Beginning JavaScript (5th Edition)</a> (21.32 €)</p><p><a href="https://www.amazon.fr/Cracking-Coding-Interview-6th-Programming/dp/0984782850">Cracking the Coding Interview (6th Edition)</a> (37.62€)</p><p><a href="http://eloquentjavascript.net/">Eloquent JavaScript</a> (Free)</p><p><a href="https://www.amazon.fr/dp/B0043D2F62/ref=dp-kindle-redirect?_encoding=UTF8&amp;btkr=1">High Performance JavaScript</a> (16.62 €)</p><p><a href="https://www.amazon.fr/JavaScript-Definitive-Guide-David-Flanagan/dp/0596805527">JavaScript: the Definitive Guide (6th Edition)</a> (19.99€)</p><p><a href="https://addyosmani.com/resources/essentialjsdesignpatterns/book/">Learning JavaScript Design Patterns</a> (Free)</p><p><a href="https://www.amazon.fr/dp/B006PW2URI/ref=dp-kindle-redirect?_encoding=UTF8&amp;btkr=1">Professional JavaScript for Web Developers (3rd Edition)</a> (21.34€)</p><h4><strong>Free Learning Apps</strong></h4><p>You will have to create an account on the majority of them to access the content</p><p><a href="https://brilliant.org/courses/computer-science-fundamentals/">Brilliant</a></p><p><a href="https://www.codecademy.com/learn/all">Codecademy</a></p><p><a href="http://try.jquery.com/">CodeSchool</a></p><p><a href="https://www.freecodecamp.org/">FreeCodeCamp</a></p><p><a href="http://javascriptissexy.com/">JavaScript is Sexy</a></p><p><a href="https://tylermcginnis.com/courses/react-fundamentals/">ReactTraining</a></p><p><a href="https://www.udacity.com/">Udacity</a></p><p><a href="https://www.vikingcodeschool.com/prep">Viking Code School Prep Work</a></p><h4><strong>Subscription-Based Learning Apps</strong></h4><p><a href="https://frontendmasters.com/">Front-End Masters</a> (33€ / month, you can cancel anytime)</p><p><a href="https://www.pluralsight.com/">PluralSight</a> (25€ / month, you can cancel anytime)</p><h4><strong>Udemy Courses</strong></h4><p>Wait for their frequent big sales where each course is 10$</p><p><a href="https://www.udemy.com/es6-bootcamp-next-generation-javascript/">Accelerated ES6 JavaScript training</a></p><p><a href="https://www.udemy.com/top-javascript-interview-questions-and-answers/?start=0">Advanced JavaScript</a></p><p><a href="https://www.udemy.com/javascript-essentials/">JavaScript Essentials </a>(Free)</p><p><a href="https://www.udemy.com/understand-javascript/">JavaScript: Understanding the Weird Parts</a></p><p><a href="https://www.udemy.com/learning-data-structures-in-javascript-from-scratch/">Learning Data Structures in JavaScript from Scratch</a></p><p><a href="https://www.udemy.com/react-redux/">Modern React with Redux</a></p><p><a href="https://www.udemy.com/the-complete-javascript-course/">The Complete JavaScript Course</a></p><p><a href="https://www.udemy.com/the-web-developer-bootcamp/">The Web Developer BootCamp</a></p><p><a href="https://www.udemy.com/webpack-2-the-complete-developers-guide/">WebPack 2: the Complete Developer Guide</a></p><h4><strong>Free Exercise / Coding Interview Apps</strong></h4><p><a href="http://exercism.io/languages/javascript/about">Exercism</a></p><p><a href="https://www.hackerrank.com/domains/tutorials/30-days-of-code">Hacker Rank</a></p><p><a href="https://javascript30.com/">JS 30</a></p><p><a href="https://leetcode.com/">LeetCode</a></p><h3><strong>DETAILED PLANNING (120 days)</strong></h3><h4><strong>Exercises (1 per day for 120 days):</strong></h4><ul><li><a href="https://javascript30.com/">JS 30</a> (<strong>30 days</strong>)</li><li><a href="https://www.hackerrank.com/domains/tutorials/30-days-of-code">Hacker Rank 30</a> (<strong>30 days</strong>)</li><li><a href="https://www.hackerrank.com/domains/tutorials/cracking-the-coding-interview">Hacker Rank — Cracking the Coding Interview</a> (<strong>20 days</strong>)</li><li><em>Cracking the Coding Interview</em> Book (<strong>40 days</strong>) (Free alternative: <a href="http://exercism.io/languages/javascript/exercises">exercism.io</a> or <a href="https://leetcode.com/">leetcode.com</a>)</li></ul><h3><strong>I. Mastering JavaScript (30 days)</strong></h3><h4><strong>Objects &amp; Prototypal Inheritance</strong></h4><ul><li>PluralSight: <a href="https://app.pluralsight.com/library/courses/javascript-objects-prototypes/table-of-contents">JavaScript Objects and Prototypes</a></li><li>Book <em>JavaScript, The Definitive Guide</em>: Chapter 6 “Objects”</li><li><a href="http://javascriptissexy.com/">javascriptissexy.com</a> : <a href="http://javascriptissexy.com/javascript-objects-in-detail/">JavaScript Objects in Detail</a></li><li>j<a href="http://javascriptissexy.com/">avascriptissexy.com</a> : <a href="http://javascriptissexy.com/javascript-prototype-in-plain-detailed-language/">JavaScript Prototype in Plain Language</a></li><li>Book <em>Professional JavaScript</em>: Chapter 6 “Object-Oriented Programming”, Section “Understanding Objects”</li><li>FreeCodeCamp: Section “Basic JavaScript”, 9 Challenges (<a href="https://www.freecodecamp.org/challenges/build-javascript-objects">Build JavaScript Objects</a>, <a href="https://www.freecodecamp.org/challenges/accessing-objects-properties-with-the-dot-operator">Accessing Objects Properties with the Dot Operator</a>, <a href="https://www.freecodecamp.org/challenges/accessing-objects-properties-with-bracket-notation">Accessing Objects Properties with Bracket Notation</a>, <a href="https://www.freecodecamp.org/challenges/accessing-objects-properties-with-variables">Accessing Objects Properties with Variables</a>, <a href="https://www.freecodecamp.org/challenges/updating-object-properties">Updating Object Properties</a>, <a href="https://www.freecodecamp.org/challenges/using-objects-for-lookups">Using Objects for Lookups</a>, <a href="https://www.freecodecamp.org/challenges/testing-objects-for-properties">Testing Objects for Properties</a>, <a href="https://www.freecodecamp.org/challenges/manipulating-complex-objects">Manipulating Complex Objects</a>, <a href="https://www.freecodecamp.org/challenges/accessing-nested-objects">Accessing Nested Objects</a>)</li></ul><h4><strong>JSON, XML &amp; APIs</strong></h4><ul><li>Book <em>Professional JavaScript</em>: Chapter 18 “XML in Javascript” and Chapter 20 “JSON”</li><li>Udemy: <a href="https://www.udemy.com/the-web-developer-bootcamp/">The Web Developer BootCamp</a>: Section 25 “Working with APIs”, Lecture 237 “JSON and XML”</li><li>Udemy: <a href="https://www.udemy.com/understand-javascript/">JavaScript: Understanding the Weird Parts</a>: Section 4 “Object and Functions”, Lecture 33 “JSON and Object Literals”</li><li>Udemy: <a href="https://www.udemy.com/top-javascript-interview-questions-and-answers/?start=0">Advanced JavaScript</a>, Section 6 “Networking”</li><li>Pluralsight: <a href="https://app.pluralsight.com/library/courses/javascript-project-json/table-of-contents">Hands-on JavaScript Project: JSON</a></li></ul><h4><strong>Regular Expressions</strong></h4><ul><li>Book <em>JavaScript, The Definitive Guide</em>: Chapter 10 “Pattern Matching with Regular Expressions”</li><li>The Coding Train: <a href="https://www.youtube.com/watch?v=7DG3kCDx53c&amp;list=PLRqwX-V7Uu6YEypLuls7iidwHMdCM6o2w">Introducing Regular Expressions</a> Series</li><li>FreeCodeCamp: Section “Basic JavaScript”, 4 Challenges ( <a href="https://www.freecodecamp.com/challenges/sift-through-text-with-regular-expressions">Sift through Text with Regular Expression</a>s, <a href="https://www.freecodecamp.com/challenges/find-numbers-with-regular-expressions">Find Numbers with Regular Expressions</a>, <a href="https://www.freecodecamp.com/challenges/find-whitespace-with-regular-expressions">Find Whitespace with Regular Expressions</a>, <a href="https://www.freecodecamp.com/challenges/invert-regular-expression-matches-with-javascript">Invert Regular Expression Matches with JavaScript</a>)</li></ul><h4><strong>Advanced DOM Manipulation</strong></h4><ul><li>Udemy: <a href="https://www.udemy.com/javascript-essentials/">JavaScript Essentials</a>, Section 4 “DOM Manipulation”</li><li>Udemy: <a href="https://www.udemy.com/the-web-developer-bootcamp/">The Web Developer BootCamp</a>, Section 14 “Advanced DOM Manipulation”</li><li><a href="http://domenlightenment.com/">DOM Enlightenment</a>: Chapters 1 to 10</li></ul><h4><strong>JavaScript Events in depth</strong></h4><ul><li>Book <em>Professional JavaScript</em>: Chapter 13 “Events”</li><li>Book <em>JavaScript, The Definitive Guide</em>: Chapter 17 “Handling Events”</li><li>Book <em>Professional JavaScript</em>: Chapter 22 “Advanced Techniques”, Section “Custom Events”</li><li>Philip Roberts: <a href="https://www.youtube.com/watch?v=8aGhZQkoFbQ">“What the heck is the Event Loop Anyway?”</a></li><li>PluralSight: <a href="https://www.pluralsight.com/courses/javascript-jquery-advanced-techniques">Advanced Techniques in JavaScript and jQuery</a>, Sections 2-3</li><li><a href="http://domenlightenment.com/">DOM Enlightenment</a>: Chapter 11</li></ul><h4><strong>jQuery</strong></h4><ul><li>Book <em>JavaScript, The Definitive Guide</em>: Chapter 19 “The jQuery Library”</li><li>FreeCodeCamp: Section “jQuery”</li><li>CodeSchool: <a href="http://try.jquery.com/">Try jQuery</a></li><li>PluralSight: <a href="https://www.pluralsight.com/courses/javascript-jquery-advanced-techniques">Advanced Techniques in JavaScript and jQuery</a>, Section 4</li></ul><h4><strong>Strict Mode</strong></h4><ul><li>Book <em>Professional JavaScript</em>: Appendix B (“Strict Mode”)</li><li>Udemy : <a href="https://www.udemy.com/understand-javascript/">JavaScript: Understanding the weird parts</a>, Section 7 “Odds and Ends”, Lessons 67 and 68</li><li>Udemy: <a href="https://www.udemy.com/top-javascript-interview-questions-and-answers/?start=0">Advanced JavaScript</a>, Section 2 “Basics”, Lesson 3</li></ul><h4><strong>Handling Errors</strong></h4><ul><li>Book <em>JavaScript, The Definitive Guide</em>: Chapter 14 “The Window Object”, Section 14.6 “Error Handling”</li><li>Book <em>Professional JavaScript</em>: Chapter 17 “Error handling and Debugging”</li><li>Book <em>Eloquent JavaScript</em>: Chapter 8 “Bugs and Error Handling”</li></ul><h4><strong>Ajax</strong></h4><ul><li>Book <em>Beginning JavaScript</em>: Chapter 14 “Ajax”</li><li>Book <em>Professional JavaScript</em>: Chapter 21 “Ajax and Comet”</li><li>Udacity: <a href="https://www.udacity.com/course/intro-to-ajax--ud110?utm_medium=referral&amp;utm_campaign=api">Introduction to Ajax</a></li><li>FreeCodeCamp: JSON APIs and Ajax</li></ul><h4><strong>Front-End Data Storage</strong></h4><ul><li>Book <em>Beginning JavaScript</em>: Chapter 13 “Data Storage”</li><li>Book <em>Professional JavaScript</em>: Chapter 23 “Offline Applications and Client-Side Storage ”</li><li>Book <em>JavaScript, The Definitive Guide</em>: Chapter 20 “Client-Side Storage”</li><li>Dive into HTML5: <a href="http://diveintohtml5.info/storage.html">Chapter 7 “The past, present and future of local storage for web applications”</a></li></ul><h4><strong>ECMAScript6</strong></h4><ul><li>Udemy: <a href="https://www.udemy.com/es6-bootcamp-next-generation-javascript/">Accelerated ES6 JavaScript training</a></li><li>PluralSight: <a href="https://www.pluralsight.com/courses/rapid-es6-training">Rapid ES6 Training</a></li><li>Udemy: <a href="https://www.udemy.com/the-complete-javascript-course/">The Complete JavaScript Course</a>, Section 7 “Get Ready for the Future: ES6 / ES2015”</li></ul><h4><strong>Object-Oriented Programming in JS</strong></h4><ul><li>Udacity: <a href="https://www.udacity.com/course/object-oriented-javascript--ud015?utm_medium=referral&amp;utm_campaign=api">Object-Oriented JavaScript</a></li><li>Book <em>Beginning JavaScript</em>: Chapter 5 “JavaScript: An Object-Oriented Language”</li><li>Book <em>Professional JavaScript</em>: Chapter 6 “Object-Oriented Programming”</li><li>Book <em>JavaScript, The Definitive Guide</em>: Chapter 9 “Classes and Modules”</li><li>j<a href="http://javascriptissexy.com/">avascriptissexy.com</a> : <a href="http://javascriptissexy.com/oop-in-javascript-what-you-need-to-know/">OOP: what you need to know</a></li><li>Udemy: <a href="https://www.udemy.com/understand-javascript/">JavaScript: Understanding the weird parts</a>, Section 5 “Object-Oriented JavaScript and Prototypal inheritance”</li><li>FreeCodeCamp: Section “Object-Oriented and Functional Programming”, 5 challenges (<a href="https://www.freecodecamp.org/challenges/declare-javascript-objects-as-variables">Declare JavaScript Objects as Variables</a>, <a href="https://www.freecodecamp.org/challenges/construct-javascript-objects-with-functions">Construct JavaScript Objects with Functions</a>, <a href="https://www.freecodecamp.org/challenges/make-instances-of-objects-with-a-constructor-function">Make Instances of Objects with a Constructor Function</a>, <a href="https://www.freecodecamp.org/challenges/make-unique-objects-by-passing-parameters-to-our-constructor">Make Unique Objects by Passing Parameters to our Constructor</a>, <a href="https://www.freecodecamp.org/challenges/make-object-properties-private">Make Object Properties Private</a>)</li></ul><h4><strong>Final Project</strong></h4><ul><li>FreeCodeCamp: <a href="https://www.freecodecamp.org/challenges/build-a-tic-tac-toe-game">Tic-Tac-Toe</a> &amp; <a href="https://www.freecodecamp.org/challenges/build-a-simon-game">Simon Game</a> projects</li></ul><h3><strong>II. Software Engineering via JavaScript (37 days)</strong></h3><h4><strong>Software engineering &amp; CS basics</strong></h4><ul><li><a href="http://Viking Code School Prep Work">Viking Code School Prep Work</a>: Chapter “Basic Prep Work”, Section 2 “Software Engineering Basics”</li><li>FrontEndMasters: <a href="https://frontendmasters.com/workshops/computer-science/">Workshop “Four Semesters of Computer Science in Six Hours”</a></li><li>Brilliant.org: <a href="https://brilliant.org/computer-science/computer-science/">Computer Science</a> Complete Course</li><li>FreeCodeCamp: “Computer Basics”</li><li>Blog Articles: <a href="https://github.com/nzakas/computer-science-in-javascript">Computer Science in JavaScript</a></li><li>Simple Programmer: <a href="https://simpleprogrammer.com/2011/01/08/solving-problems-breaking-it-down/">Approaching problems, breaking it down</a></li><li>FreeCodeCamp: “Big O Notation”</li><li>CodeCademy: <a href="https://www.codecademy.com/courses/big-o/0/1">Big O</a></li></ul><h4><strong>Algorithm and Data Structures</strong></h4><ul><li>Udemy: <a href="https://www.udemy.com/learning-data-structures-in-javascript-from-scratch/">Learning Data Structures in JavaScript from Scratch</a></li><li>FrontEndMasters: <a href="https://frontendmasters.com/workshops/algorithms-data-structures-js/">Algorithms and Data Structures in JavaScript</a></li><li>Free Code Camp: Algorithm Scripting (Beginner, Intermediate and Advanced)</li></ul><h4><strong>JS Design Patterns</strong></h4><ul><li>Book <a href="https://addyosmani.com/resources/essentialjsdesignpatterns/book/"><em>Learning JavaScript Design Patterns</em></a></li><li>PluralSight: <a href="https://www.pluralsight.com/courses/javascript-practical-design-patterns">Practical Design Patterns in JavaScript</a></li><li>PluralSight: <a href="https://www.pluralsight.com/courses/javascript-design-patterns">JavaScript Design Patterns</a></li></ul><h4><strong>Functional Programming</strong></h4><ul><li>FunFunFunction: <a href="https://www.youtube.com/watch?v=BMUiFMZr7vk&amp;list=PL0zVEGEvSaeEd9hlmCXrk5yUyqUag-n84">Functional Programming in JavaScript</a> Series</li><li><a href="https://github.com/getify/Functional-Light-JS">Functional Light JS</a></li></ul><h4><strong>Final Project</strong></h4><ul><li><a href="http://web-engineering.info/tech/JsFrontendApp/book/index.html">Build a Vanilla JavaScript Web App</a></li></ul><h3><strong>III. Front-end Development Tools &amp; Architecture (23 days)</strong></h3><h4><strong>JS templating (Handlebars.js)</strong></h4><ul><li>j<a href="http://javascriptissexy.com/">avascriptissexy.com</a> : <a href="http://javascriptissexy.com/handlebars-js-tutorial-learn-everything-about-handlebars-js-javascript-templating/">Handelbar.js Tutorial</a></li><li>PluralSight: <a href="https://www.pluralsight.com/courses/handlebars-javascript-templating">JavaScript Templating with Handlebars</a></li></ul><h4><strong>Tooling &amp; Automation</strong></h4><ul><li>PluralSight: <a href="https://www.pluralsight.com/courses/javascript-build-automation-gulpjs">JavaScript Build Automation With Gulp.js</a></li></ul><h4><strong>JS Module loaders / bundlers (Webpack)</strong></h4><ul><li>Udemy: <a href="https://www.udemy.com/webpack-2-the-complete-developers-guide/">WebPack 2: the Complete Developer Guide</a></li><li>PluralSight: <a href="https://www.pluralsight.com/courses/javascript-development-environment">Building a JavaScript Development Environment</a></li></ul><h4><strong>Principles of a Single Page Application</strong></h4><ul><li><a href="http://marcobotto.com/frontend-javascript-single-page-application-architecture/">Front-End JavaScript Single Page Application Architecture</a></li><li><a href="https://www.youtube.com/watch?v=vXjVFPosQHw">Nicholas Zakas: Scalable JavaScript Application Architecture</a></li><li><a href="https://tutorialzine.com/2015/02/single-page-app-without-a-framework">Making a Single Page App Without a Framework</a></li></ul><h4><strong>Architecting Front-End Web Applications</strong></h4><ul><li>Book <em>Eloquent JavaScript</em>: <a href="http://eloquentjavascript.net/10_modules.html">Chapter 10 “Modules”</a></li><li>Udemy: <a href="https://www.udemy.com/understand-javascript/">JavaScript: Understanding the Weird Parts</a>, Sections 8 and 9</li><li>Udemy: <a href="https://www.udemy.com/the-complete-javascript-course/">The Complete JavaScript Course</a>, Section 6 “The Budget App project”</li></ul><h4><strong>Testing for Front-End Developers</strong></h4><ul><li>PluralSight: <a href="https://www.pluralsight.com/courses/testing-and-prototyping-javascript-apps">Front-End First: Testing and Prototyping JavaScript Apps</a></li><li>Udacity: <a href="https://www.udacity.com/course/javascript-testing--ud549">JavaScript Testing</a></li></ul><h4><strong>High Performing Code in JS</strong></h4><ul><li>Book <em>High Performance JavaScript: Build Faster Web Application Interfaces</em></li></ul><h3><strong>IV. React &amp; Redux (16 days)</strong></h3><ul><li>TylerMcGinnis: <a href="https://tylermcginnis.com/courses/react-fundamentals/">React Fundamentals</a></li><li>Udemy: <a href="https://www.udemy.com/react-redux/">Modern React with Redux</a></li><li>PluralSight: <a href="https://www.pluralsight.com/courses/react-redux-react-router-es6">Building Applications with React and Redux in ES6</a></li></ul><h3><strong>V. Go further (14 days)</strong></h3><h4><strong>Progressive Web Apps</strong></h4><ul><li><a href="https://www.smashingmagazine.com/2016/08/a-beginners-guide-to-progressive-web-apps/">A Beginner’s Guide to Progressive Web Apps</a></li><li>Udacity: <a href="https://www.udacity.com/course/intro-to-progressive-web-apps--ud811">Intro to Progressive Web Apps</a></li><li>PluralSight: <a href="https://www.udacity.com/course/intro-to-progressive-web-apps--ud811">Getting Started with Progressive Web Apps</a></li></ul><h4><strong>Site Performance Optimization</strong></h4><ul><li>Udacity: <a href="https://www.udacity.com/course/browser-rendering-optimization--ud860">Browser Rendering Optimization</a></li><li>Udacity: <a href="https://www.udacity.com/course/website-performance-optimization--ud884">WebSite Performance Optimization</a></li></ul><h4><strong>SASS</strong></h4><ul><li>PluralSight: <a href="https://app.pluralsight.com/library/courses/better-css/table-of-contents">A Better CSS: LESS and SASS</a></li></ul><h4><strong>SEO Fundamentals</strong></h4><ul><li>PluralSight: <a href="https://app.pluralsight.com/library/courses/seo-fundamentals/table-of-contents">SEO Fundamentals</a></li></ul><h4><strong>Get the job</strong></h4><ul><li>PluralSight: <a href="https://app.pluralsight.com/library/courses/developer-job-interviews/table-of-contents">Preparing for a Job Interview</a></li><li><a href="http://Viking Code School Prep Work">Viking Code School Prep Work</a>: Chapter “Getting Hired Phase 1”</li><li>PluralSight: <a href="https://app.pluralsight.com/library/courses/job-search-strategies/table-of-contents">Designing a Killer Job Search Strategy</a></li><li>PluralSight: <a href="https://app.pluralsight.com/library/courses/get-involved/table-of-contents">Get Involved!</a></li></ul><h3><strong>SOME TIPS</strong></h3><p>While learning, be sure to <strong>write and reproduce most of the code</strong> you will encounter, and to practice as much as possible.</p><p>Push as much code as you can on Github: having <strong>long streaks of public commits for extended periods of time</strong> says a lot about your grit and passion for code. It will reflect very well when you get to the phase of the real interviews.</p><p>When you really don’t understand a key concept: <strong>take 1 or 2 days to write an in-depth article about it</strong>. It will force you to seek out external resources and to try and understand from various explanations. Write the article as if you were explaining the concept to someone who is a true beginner and doesn’t have background on the topic. This helped me a lot grasp many parts of JavaScript and is known to be amongst the best methods to understand and retain difficult concepts.</p><p>Don’t be a perfectionist: <strong>be clever about what is most suited to your needs</strong>. Spending 10 days on the quirks of Regular Expressions will not be very useful if you don’t intend to use them in the coming weeks. Understand what they are and move on: when the necessity to use them comes you will have the opportunity to go deeper and learn all the details about them.</p><p>Try to reach to solutions by yourself but don’t get stuck: <strong>get help on </strong><a href="https://stackoverflow.com/"><strong>StackOverflow</strong></a><strong> or in the </strong><a href="https://gitter.im/FreeCodeCamp/FreeCodeCamp"><strong>FreeCodeCamp community group</strong></a> when you can’t move forward.</p><p>If you want to join me in this program and share your best resources for learning, use the hashtag <strong>#120DaysBetterDev</strong> on Twitter: let’s encourage each other and code together!</p><figure><a href="http://eepurl.com/dvio9L"><img alt="" src="https://cdn-images-1.medium.com/max/690/1*td_Zl-oX7vl2kIsoldqcLA.png" /></a></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c3bbbdf31ee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/a-120-days-plan-to-become-a-better-developer-120daysbetterdev-4c3bbbdf31ee">A 120 Days Plan to Become a Better Developer #120DaysBetterDev</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Work with JavaScript arrays like a boss]]></title>
            <link>https://medium.com/hackernoon/work-with-javascript-arrays-like-a-boss-97207a042e42?source=rss-d67581bfc14b------2</link>
            <guid isPermaLink="false">https://medium.com/p/97207a042e42</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Léna Faure]]></dc:creator>
            <pubDate>Sun, 02 Jul 2017 11:49:07 GMT</pubDate>
            <atom:updated>2019-05-15T12:00:52.004Z</atom:updated>
            <content:encoded><![CDATA[<h4>Know once and for all how to index, add and delete elements in arrays</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZphA6Bn4EtFf5UBSKqd-OA.jpeg" /><figcaption>Steinar Engeland — <a href="https://unsplash.com/">https://unsplash.com</a></figcaption></figure><p>The Array in <a href="https://hackernoon.com/tagged/javascript">JavaScript</a> is a global object which contains a list of items.</p><p>It is similar to any variable, in that you can use it to hold any type of data. However, it has one important difference: it can hold <em>more than one item</em> of data at a time.</p><p>An array is <strong>an ordered collection of values</strong>: each value is called an <strong>element</strong>, and each element has a numeric position in the array, known as its <strong>index</strong>.</p><p>An element inside an array can be of any type, and <em>different elements of the same array can be of different types</em> : string, <a href="https://hackernoon.com/tagged/boolean">boolean</a>, even objects or other arrays. This means that it’s possible to create an array that has a string in the first position, a number in the second, an object in the third, and so on.</p><p>Arrays in Javascript are <strong>zero-based</strong>, which means that the index of the first element is 0. This is very important, because it means that there always will be an offset of one unit: the first element has an index of 0, the second element has an index of 1, and so on.</p><p>Here is a scheme of an array with different types of elements :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*zpOOm4aaMZWeDwbmThrmBA.png" /></figure><p>Here at index 0 we find a string, at index 1 an integer, at index 2 a boolean, and at index 3 another array. This comes in very handy when you need to store collections of data in one place; now let’s see how to create and work with arrays.</p><h3>Declare an array</h3><p>Arrays can be very useful since <strong>you can store as many items of data in an array as you want</strong> (within the limits of the language, which is 2^(32) elements).</p><p>So how do you create an array ? You need to declare a variable with the var keyword, but the syntax to define the values of the array is very specific : you have to tell Javascript that you want it to be an array.</p><p>To do so, you have two choices : the array literal [] or the new keyword.</p><h4>Short syntax : with the array literal notation []</h4><p>The array literal notation is simply a comma-separated list of array elements within square brackets.</p><pre>var myArray = [ &quot;Jack&quot;, &quot;Sawyer&quot;, &quot;John&quot;, &quot;Desmond&quot; ];</pre><p>The content of the array is defined between the opening and the closing brackets, and each value is separated by a comma.</p><p>Values are introduced in the same way as simple variables, meaning for example that strings must be declared between quotation marks.</p><p>To define a new empty array you just have to use empty brackets :</p><pre>var myArray = [];</pre><h4>Long syntax : with the Array() constructor</h4><pre>var lostArray = new Array(&quot;Jack&quot;, &quot;Sawyer&quot;, &quot;John&quot;, &quot;Desmond&quot; );<br>var twinPeaksArray = new Array(&quot;Laura&quot;, 2, [&quot;Bob&quot;, &quot;Leland&quot;, &quot;Dale&quot;]);</pre><p>The <em>new</em> keyword of this syntax asks Javascript to define a new Array, whose items are passed as parameters.</p><p>If you know in advance how many elements the array will contain, you can pass the count as a parameter to the constructor, and the array will automatically be created with that number of slots for elements (each element will be initialized with the value undefined) :</p><pre>var myArray = new Array(80);</pre><p>This will create an empty array with 80 slots initialized with the value undefined.</p><p>To define a new empty array with no particular number of items you can just initialize a new array with no parameters :</p><pre>var myArray = new Array();</pre><h3>Access elements of an array</h3><p>The index value of each element allows you to refer to each piece of data inside your array : you can access it using the [] operator :</p><pre>var myArray = [&quot;Jack&quot;, &quot;Sawyer&quot;, &quot;John&quot;, &quot;Desmond&quot;];</pre><pre>console.log(myArray[0]); // Prints “Jack”<br>console.log(myArray[3]); // Prints “Desmond”</pre><p>Remember that the index values start at 0, not 1. This means that array indexes start at 0 and go up to the number of elements, minus 1. So, our array of four elements has indexes from 0 to 3.</p><p>As we saw, arrays can have several dimensions, which means that an array element can contain an array, whose elements can contain arrays, etc. So how do I access these arrays inside arrays, or multidimensional arrays ?</p><p>Let’s take the example of an array representing a family, where the children of the family are contained in their own array inside the main array :</p><pre>var familyArray = [&quot;Marge&quot;, &quot;Homer&quot;, [&quot;Bart&quot;, &quot;Lisa&quot;, &quot;Maggie&quot;]];</pre><p>We could represent this array like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*rGnhZrNi9bJvnlvr_L1-sg.png" /></figure><p>If I want to access the value “Lisa”, how will I manage to to that ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*3DMsgphGNF46jtrxiKCDCA.png" /></figure><p>We can visualize the position of “Lisa” here in orange : at index 1 inside the nested array, itself positioned at index 2 of the main array :</p><p>To access the “Lisa” value, I will then write :</p><pre>var lisa = familyArray[2][1];</pre><pre>console.log(lisa); // Prints &quot;Lisa&quot;</pre><p>This can go on almost indefinitely, and allow us to store very well organized collections of data nested inside one another, that will be accessible via their indexes.</p><h3>Add items to an array</h3><h4>Adding an index</h4><p>We saw that you can access every element in in array by calling its corresponding index. This also allows us to add (or modify) elements by declaring for example :</p><pre>var myArray = [ &quot;Kate&quot;, &quot;Sun&quot;];<br>myArray[2] = &quot;Juliet&quot;;</pre><pre>console.log(myArray); // Prints &quot;Kate, Sun, Juliet&quot;</pre><p>Here I simply added an element at index 2 of the array, which didn’t exist before but now contains the value “Juliet”.</p><p>What happens if I declare an element at a given index and there are no elements in-between ? The array will create all the elements and initialize those that don’t have a value with undefined:</p><pre>var myArray = [&quot;Kate&quot;, &quot;Sun&quot;];</pre><pre>myArray[5] = &quot;Juliet&quot;;<br>console.log(myArray.length); // Prints &quot;6&quot;<br>console.log(myArray); // Prints [&quot;Kate&quot;, &quot;Sun&quot;, undefined, undefined, undefined, &quot;Juliet&quot;]</pre><p>You can find the length of an array by using the Array property called length: here we can see that the array has now six elements, and the three elements that have not been assigned a value are undefined.</p><h4>The push() method</h4><p>The push() method allows to add one or several items to an array. The push() method can receive an unlimited number of parameters, and each parameter represents an item to add at the end of the array.</p><pre>var myArray = [ &quot;Kate&quot;, &quot;Sun&quot;];</pre><pre>myArray.push(&quot;Juliet&quot;); // Adds &quot;Juliet&quot; at the end of the array<br>myArray.push(&quot;Libby&quot;, &quot;Shannon&quot;);// Adds &quot;Libby&quot; and &quot;Shannon&quot; at the end of the array.</pre><pre>console.log(myaArray); // Prints [&quot;Kate&quot;, &quot;Sun&quot;, &quot;Juliet&quot;, &quot;Libby&quot;, &quot;Shannon&quot;]</pre><h4>The unshift() method</h4><p>The unshift() method works like push(), except that the items are added at the beginning of the array.</p><pre>var myArray = [ &quot;Kate&quot;, &quot;Sun&quot;];</pre><pre>myArray.unshift(&quot;Juliet&quot;); // Adds &quot;Juliet&quot; at the beginning of the array<br>myArray.unshift(&quot;Libby&quot;, &quot;Shannon&quot;);// Adds &quot;Libby&quot; and &quot;Shannon&quot; at the beginning of the array.</pre><pre>console.log(myaArray); // Prints [&quot;Libby&quot;, &quot;Shannon&quot;, &quot;Juliet&quot;, &quot;Kate&quot;, &quot;Sun&quot;]</pre><h3>Suppress items from an array</h3><p>The pop() and shift() methods</p><p>They respectively remove the last and first element from the array :</p><pre>var myArray = [&quot;Jack&quot;, &quot;Sawyer&quot;, &quot;John&quot;, &quot;Desmond&quot;, &quot;Kate&quot;];</pre><pre>myArray.pop(); // Removes &quot;Kate&quot;<br>myArray.shift(); // Removes &quot;Jack&quot;</pre><pre>console.log(myArray); // Prints [&quot;Sawyer&quot;, &quot;John&quot;, &quot;Desmond&quot;]</pre><h3>The splice() method</h3><p>The splice() method allows us to add/remove items to/from an array, and to specifically indicate the index of the elements that have to be added /removed :</p><p>In the following example, splice adds two elements starting at index 2 (the third element):</p><pre>var fruitArray = [&quot;apple&quot;, &quot;peach&quot;, &quot;orange&quot;, &quot;lemon&quot; ,&quot;lime&quot;, &quot;cherry&quot;]; <br>fruitArray.splice(2, 0, &quot;melon&quot;, &quot;banana&quot;);</pre><pre>console.log(fruitArray); // Prints [&quot;apple&quot;, &quot;peach&quot;, &quot;melon&quot;, &quot;banana&quot;, &quot;orange&quot;, &quot;lemon&quot;, &quot;lime&quot;, &quot;cherry&quot;]</pre><ul><li>The first parameter is the index : it specifies at what position of the array to add/remove items. Here we chose the index 2 (with the value “orange”).</li><li>The second parameter is number of items to be removed. Here we set it to 0, so no items will be removed.</li><li>The following optional parameters are the new item(s) to be added to the array. Here we want to add “melon” and “banana” starting at index 2.</li></ul><p>To remove only one element at index 2 (“orange”) for example, I would have to write :</p><pre>var fruitArray = [&quot;apple&quot;, &quot;peach&quot;, &quot;orange&quot;, &quot;lemon&quot; ,&quot;lime&quot;, &quot;cherry&quot;]; <br>fruitArray.splice(2,1);</pre><pre>console.log(fruitArray); // Prints [&quot;apple&quot;, &quot;peach&quot;, &quot;lemon&quot;, &quot;lime&quot;, &quot;cherry&quot;]</pre><p>Check out also the slice() method for another way to remove items from an array, but that will this time return a <em>new </em>array instead of modifying the original.</p><p>Want to learn more ? Check out my other articles on the basics of <a href="https://hackernoon.com/tagged/JavaScript">JavaScript</a>:</p><ul><li><a href="https://hackernoon.com/hoisting-in-javascript-a-quick-guide-cc4d9597bbd7"><strong>Hoisting in JavaScript: a Quick Guide</strong></a></li><li><a href="https://hackernoon.com/understand-javascript-variable-scope-with-ease-221a6d41dc43"><strong>Understand JavaScript Variable Scope with ease</strong></a></li><li><a href="https://hackernoon.com/get-your-head-around-this-73c23653b102"><strong>Get your head around “this”</strong></a></li><li><a href="https://hackernoon.com/how-to-use-javascript-closures-with-confidence-85cd1f841a6b"><strong>How to use JavaScript closures with confidence</strong></a></li><li><a href="https://hackernoon.com/grasp-by-value-and-by-reference-in-javascript-7ed75efa1293"><strong>Grasp “By Value” and “By Reference” in JavaScript</strong></a></li><li><a href="https://hackernoon.com/a-quick-handbook-for-dates-in-javascript-7b71d0ef8e53"><strong>A Quick Handbook for Dates in JavaScript</strong></a></li></ul><p>I hope you enjoyed this quick overview of working with arrays in JavaScript.</p><p>Feel free to comment and like this article so that others can find it easily on Medium !</p><figure><a href="http://eepurl.com/dvio9L"><img alt="" src="https://cdn-images-1.medium.com/max/690/1*td_Zl-oX7vl2kIsoldqcLA.png" /></a></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97207a042e42" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/work-with-javascript-arrays-like-a-boss-97207a042e42">Work with JavaScript arrays like a boss</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Quick Handbook for Dates in JavaScript]]></title>
            <link>https://medium.com/hackernoon/a-quick-handbook-for-dates-in-javascript-7b71d0ef8e53?source=rss-d67581bfc14b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b71d0ef8e53</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Léna Faure]]></dc:creator>
            <pubDate>Sun, 18 Jun 2017 14:02:02 GMT</pubDate>
            <atom:updated>2019-05-15T12:00:53.159Z</atom:updated>
            <content:encoded><![CDATA[<h4>JavaScript has a built-in <strong>Date </strong>object that represents time. How can you use it and when will it be useful ?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LpdtaTotsKYTdYTPxsoXIQ.jpeg" /><figcaption>Han Chau — unsplash.com</figcaption></figure><p>Suppose you are building an application that displays all the timetables of buses and trains in your area. The user can select a <a href="https://hackernoon.com/tagged/journey">journey</a>, and you want to be able to tell him how long his trip will take. To do so, you will have to take the arrival time and subtract it from the departure time.</p><p>Simply using the written expression of hours won’t be effective : how will you manage to calculate the journey of a night train leaving at 8pm and arriving at 7:58am the next morning? How will you handle the Orient-Express that leaves at 20h50 from Nice and arrives in Moscow nearly two days later ?</p><p>You have to have <strong>a unique representation of these two specific points in time</strong>, and this is where the Date Object comes in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*owGTLUFmN7Z-lSXk0r9yKA.jpeg" /><figcaption>Ugur Akdemir — unsplash.com</figcaption></figure><p><strong>The Date object in Javascript stores a unique representation of each date</strong>: an extremely large number, which holds the number of milliseconds from 01 January, 1970 00:00:00 Universal Time (UTC), also called Epoch Time. To put it in perspective, one day contains 86,400,000 milliseconds…</p><p>Rather than understanding the concepts of dates and times, computers simply record every point in time since the Epoch time. In <a href="https://hackernoon.com/tagged/javascript">Javascript</a>, when the current date is requested, it is then returned as the number of milliseconds elapsed since January 1, 1970 00:00:00.</p><blockquote>January 1st, 1970 is when it all began</blockquote><p>Javascript enables you to create a Date object initialized at a specific time and date, or simply reflecting the current system time on the computer on which the browser is running.</p><h4><strong>There are two important things to be aware of when working with the Javascript Date object</strong>:</h4><ul><li>When reflecting the date and time from a browser <em>you are completely bound to the user’s computer day and time</em>: if the user did not set the date right on his computer, your Date object will reflect these false settings.</li><li>Whilst you can read the system date and time set on the user’s computer, and set your own changes inside your Date object according to the date your read from the computer, you <em>cannot</em> change the computer’s system date and time: the user’s system date and time will always remain unchanged.</li></ul><p>While working on your own instance of the Date object representing a specific date, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object. But in this article we will focus only on the <em>creation</em> phase of the Date object.</p><h4>How to construct Date objects ?</h4><p>A Javascript Date object is created much like any other in Javascript: using the <em>new</em> keyword and some optional arguments to initialize an instance (your own copy) of the Date object.</p><p>The syntax for creating your Date() object is as follows:</p><pre>var myDate = new Date(optional parameters);</pre><h3>Good to know</h3><ul><li>Independent of input format, Javascript will, by default, output dates in full text string format, according to the timezone you are in, for example :</li></ul><pre>Fri Sep 02 2016 17:24:56 GMT+0200 (CEST)</pre><ul><li>When passing the right arguments to the Date object constructor, you will obtain the representation of the corresponding point in time relative to Epoch Time. However, as stated before, <strong>the computer date will be relative to your timezone, and the javascript Date object uses the date set on your computer to output its result</strong>.</li></ul><p>Once your Date object is created, you have two ways of constructing the date you want to reflect: <strong>passing parameters to the instance of the Date object you created</strong>, or <strong>using the set methods that are native to the Javascript Date object</strong>.</p><p>Let’s discuss here how you can implement these two methods.</p><h3>I. Passing parameters to an instance of a Date Object</h3><p>Javascript offers four ways to create a Date object :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80b0f50ba4012eb84f209996d6a5643e/href">https://medium.com/media/80b0f50ba4012eb84f209996d6a5643e/href</a></iframe><p><strong>1/ Passing no arguments at all, which will generate the current date, to the millisecond</strong></p><pre>var today = new Date();<br>// Prints Sun Jun 18 2017 17:24:56 GMT+0200 (CEST)</pre><p>If no arguments are provided, it creates an object for the current date and time. Passing no argument will display the current date as interpreted by my browser given the settings of my computer.</p><p><strong>2/ Passing a number corresponding to the number of milliseconds since Epoch time</strong></p><pre>var  milliseconds = new Date(5000); <br>// Prints Thu Jan 01 1970 01:00:05 GMT+0100 (CET)</pre><p>Passing the argument 5000 will create a date that represents five seconds past midnight on January 1st, 1970.</p><p><strong>3/ Passing a string with a very specific format that will be interpreted as a date</strong></p><pre>var dateAsString = new Date(dateString);</pre><p>There are generally <strong>4 types of Javascript string input formats</strong> for the Date object :</p><h4><strong>ISO date (the international standard), written as : “2016–09–02”</strong>.</h4><p>ISO 8601 is the international standard for the representation of dates and times. When passing a string to a Date object in Javascript, it is the preferred date format.</p><p>Examples :</p><p>→ Complete date (YYYY-MM-DD)</p><pre>var dateISO = new Date(“2016–03–25”); <br>// Prints Fri Mar 25 2016 01:00:00 GMT+0100 (CET)</pre><p>→ Year and month (YYYY-MM)</p><pre>var dateISO = new Date(&quot;2016-03&quot;); <br>// Prints Tue Mar 01 2016 01:00:00 GMT+0100 (CET)</pre><p>→ Year (YYYY)</p><pre>var dateISO = new Date(&quot;2016&quot;);<br>// Prints Fri Jan 01 2016 01:00:00 GMT+0100 (CET)</pre><p>→ With added hours, minutes and seconds (YYYY-MM-DDTHH:MM:SS)</p><pre>var dateISO = new Date(&quot;2016-03-25T12:00:00&quot;);<br>// Prints Fri Mar 25 2016 13:00:00 GMT+0100 (CET)</pre><h4>Short dates, written as : “03/25/2015” or “2015/03/25”</h4><p>Short dates are more often passed to the Date object with the “MM/DD/YYYY” syntax, but can also be written as “YYYY/MM/DD”.</p><p>→ “MM/DD/YYYY” format</p><pre>var dateShort = new Date(&quot;03/25/2016&quot;);<br>// Prints Fri Mar 25 2016 00:00:00 GMT+0100 (CET)</pre><p>→ “YYYY/MM/DD” format</p><pre>var dateShort = new Date(&quot;2016/03/25&quot;);<br>// Prints Fri Mar 25 2016 00:00:00 GMT+0100 (CET)</pre><h3>Good to know</h3><ul><li>Month is written before day in all short date and ISO date formats.</li><li>If you write month and day numbers without a leading zero (2 instead of 02 for example), they will still be interpreted and output the right date)</li></ul><h4>Long dates, written as : “Mar 25 2016” or “25 March 2016”.</h4><p>The most used syntax for long dates string format is “Day Month Year”. However, day, month and year names can be written in any order.</p><p>Month names can be written in full (March) or abbreviated (Mar) and are case insensitive.</p><p>One more thing to take note of: if you add commas or any kind of separator inside the string, they will be ignored.</p><pre>var date1 = new Date(&quot;3 march 2016&quot;); <br>var date2 = new Date(&quot;3 MARCH, 2016&quot;);<br>var date3 = new Date(&quot;2016 3 March&quot;);<br>var date4 = new Date(&quot;3 2016 mar&quot;);<br>var date5 = new Date(&quot;March 2016 3&quot;);<br>var date6 = new Date(&quot;March*2016,3&quot;);</pre><pre>// All of the above will print Thu Mar 03 2016 00:00:00 GMT+0100 (CET)</pre><h4>Full date, written as : “Thursday March 03 2016”.</h4><p>JavaScript will accept date strings in “full JavaScript format”, which is the same format that is used for outputting the content of a Date object.</p><pre>var dateFull = new Date(&quot;Mon Mar 02 2015 00:00:00 GMT+0100 (CET)&quot;);<br>// Prints Mon Mar 02 2015 00:00:00 GMT+0100 (CET)</pre><p>Timezone-related parenthesis like (CET) in our example are optional and will be ignored if erroneous.</p><h3>Good to know</h3><h4><strong>String parameters and Timezones: be aware</strong></h4><p>When you pass a string representing a date for example, if no timezone is specified, this date will be converted to match the timezone you are in.<br>In other words: If a date/time is created in GMT (Greenwich Mean Time), the date/time will be converted to CDT (Central US Daylight Time) if a user browses from central US.</p><p>Thus, when you pass for example :</p><pre>var newYear = new Date(“2016”);</pre><p>Depending on the timezone your are in, the output could vary between December 31 2015 and January 01 2016.</p><h4>String parameters are converted to numbers by the Date object</h4><p>When a string is passed as a parameter to the Date object, it is then converted into a number (number of milliseconds since Epoch Time).</p><p>If the string format is illegal and not accepted by the Date object, the parameter will be passed as “NaN” (Not a Number) and result in an “Invalid date” error.</p><p><strong>4/ Passing every argument in the right order, separated by a comma</strong></p><pre>var d = new Date(year, month, day [,hour,minute,second,millisecond ]);</pre><p>All these parameters are integers, each representing a chunk of the full date javascript formatting.</p><p>While the first three arguments (year, month and day) are in principle mandatory, Javascript can interpret the date if you pass only the year and month arguments. In that case, the 3rd argument (day) will be interpreted as equal to 1.</p><p>The last four arguments (hour, minute, second, millisecond) are optional and taken to 0 if not specified. When one of these four optional arguments is specified, all the other arguments to its left must also be specified.</p><p>→ Be careful : If you give the Date object a single argument, that argument will be treated as a millisecond count, not as the first parameter (year).</p><p>Let’s review these arguments one by one and see how they can be used as parameters of a Date object:</p><h4><strong>→ year</strong></h4><p>Specify the year in full (use 1998 instead of 98 for example). However, be aware that if you use a two-digit date between 0 and 99, 1900 will be added to the integer (98 will become 1998).</p><h4>→ month</h4><p>The month parameter is zero-based (contrary to the day parameter). The integer will therefore be comprised between 0 (January) and 11 (December)</p><h4>→ day</h4><p>The day parameter represents the day of the month. It begins at 1 (contrary to the month parameter) and the integer will be comprised between 1 and 31.</p><h4>→ hour</h4><p>The hour parameter represents the hour of the day on a 24 hours scale. The integer will be comprised between 0 and 23.</p><h4>→ minute</h4><p>The minute parameter is on a 60 minutes scale. The integer will be comprised between 0 and 59.</p><h4>→ second</h4><p>The second parameter is on a 60 seconds scale. The integer will be comprised between 0 and 59.</p><h4>→ millisecond</h4><p>The millisecond parameter is on a 1000 milliseconds scale. The integer will be comprised between 0 and 999.</p><pre>var theDate = new Date(2016,6,17,21,15,30,0);<br>// Prints Sun Jul 17 2016 21:15:30 GMT+0200 (CEST)</pre><p>Note that the month number (6) corresponds to July and not June, due to the <strong>zero-based structure of the month parameter</strong>.</p><h3>II. Using the “set” methods that set a component’s value within a Date</h3><p>The Date object’s methods, that can be used on an instance of date, feature set methods for setting specific components of the date. <br>These methods let you set values for a part of the date : years, months, days, hours, minutes, seconds and milliseconds.</p><p>Let’s create for example an instance of the Date object that will represent the current date, and review the set methods we can apply to this newly created myDate variable :</p><pre>var myDate = new Date();<br>// Prints Sat Sep 03 2016 16:22:20 GMT+0200 (CEST)</pre><h4>→ setFullYear()</h4><p>Sets the year (optionally month and day)</p><pre>myDate.setFullYear(2001);<br>// Prints Mon Sep 03 2001 16:28:40 GMT+0200 (CEST)</pre><h4>→ setMonth()</h4><p>Sets the month (0–11)</p><pre>myDate.setMonth(2);<br>// Prints Thu Mar 03 2016 16:33:48 GMT+0100 (CET)</pre><h4>→ setDate()</h4><p>Sets the day of the month as a number (1–31)</p><pre>myDate.setDate(25);<br>// Prints Sun Sep 25 2016 16:22:20 GMT+0200 (CEST)</pre><h4>→ setHours()</h4><p>Sets the hour (0–23)</p><pre>myDate.setHours(9);<br>// Prints Sat Sep 03 2016 09:31:23 GMT+0200 (CEST)</pre><h4>→ setMinutes()</h4><p>Sets the minutes (0–59)</p><pre>myDate.setMinutes(1);<br>// Prints Sat Sep 03 2016 16:01:02 GMT+0200 (CEST)</pre><h4>→ setSeconds()</h4><p>Sets the seconds (0–59)</p><pre>myDate.setSeconds(30);<br>// Prints Sat Sep 03 2016 16:36:30 GMT+0200 (CEST)</pre><h4>→ setMilliseconds():</h4><p>Sets the milliseconds (0–999)</p><h4>→ setTime()</h4><p>Sets the time in milliseconds since January 1, 1970</p><h3>Conclusion</h3><p>You have many options at your service to build your own instance of the Date object in Javascript, and even more ways of retrieving and displaying it with native built-in methods.</p><p>What can be puzzling when manipulating dates is the management of the different timezones users find themselves in, along with the lack of control on the user’s computer settings.</p><p>From blog comments to online orders to booking calendars however, the right use of Date object is one of the most important Javascript components that make for trusted and reliable web applications.</p><p>Want to learn more ? Check out my other articles on the basics of JavaScript:</p><ul><li><a href="https://hackernoon.com/hoisting-in-javascript-a-quick-guide-cc4d9597bbd7"><strong>Hoisting in JavaScript: a Quick Guide</strong></a></li><li><a href="https://hackernoon.com/understand-javascript-variable-scope-with-ease-221a6d41dc43"><strong>Understand JavaScript Variable Scope with ease</strong></a></li><li><a href="https://hackernoon.com/get-your-head-around-this-73c23653b102"><strong>Get your head around “this”</strong></a></li><li><a href="https://hackernoon.com/how-to-use-javascript-closures-with-confidence-85cd1f841a6b"><strong>How to use JavaScript closures with confidence</strong></a></li><li><a href="https://hackernoon.com/grasp-by-value-and-by-reference-in-javascript-7ed75efa1293"><strong>Grasp “By Value” and “By Reference” in JavaScript</strong></a></li><li><a href="https://medium.com/@lenafaure/work-with-javascript-arrays-like-a-boss-97207a042e42"><strong>Work with JavaScript arrays like a boss</strong></a></li></ul><p>I hope you enjoyed this explanation of Dates in JavaScript.</p><p>Feel free to comment and like this article so that others can find it easily on Medium !</p><figure><a href="http://eepurl.com/dvio9L"><img alt="" src="https://cdn-images-1.medium.com/max/690/1*td_Zl-oX7vl2kIsoldqcLA.png" /></a></figure><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b71d0ef8e53" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/a-quick-handbook-for-dates-in-javascript-7b71d0ef8e53">A Quick Handbook for Dates in JavaScript</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grasp “By Value” and “By Reference” in JavaScript]]></title>
            <link>https://medium.com/hackernoon/grasp-by-value-and-by-reference-in-javascript-7ed75efa1293?source=rss-d67581bfc14b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ed75efa1293</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Léna Faure]]></dc:creator>
            <pubDate>Sun, 04 Jun 2017 15:53:29 GMT</pubDate>
            <atom:updated>2019-05-15T12:00:53.622Z</atom:updated>
            <content:encoded><![CDATA[<h4>And learn why it’s crucial to know the difference</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sT1WaL6NwK0a-tauBeRXzA.jpeg" /><figcaption><a href="https://unsplash.com/">https://unsplash.com/</a></figcaption></figure><p><a href="https://hackernoon.com/tagged/javascript">JavaScript</a> is an Object-Oriented language: this means that most things in JavaScript are <strong>Objects</strong>. For example, functions are Objects. The only elements that are not objects are the <strong>Primitive Data Types : </strong><em>string</em>, <em>number</em>, <em>boolean</em>, <em>null</em> and <em>undefined.</em> These Primitive Data Types also are<em> </em><strong>immutable</strong>, which means that once created they cannot be modified.</p><p>One of the differences between the two is that Primitive Data Types are passed <em>By Value</em> and Objects are passed <em>By Reference</em>.</p><blockquote>Primitive Data Types are passed <em>By Value</em> and Objects are passed <em>By Reference.</em></blockquote><p>What does this mean ? You can think of it this way:</p><ul><li><strong>By Value means creating a COPY of the original</strong>. Picture it like twins: they are born exactly the same, but the first twin doesn’t lose a leg when the second twin loses his in the war.</li><li><strong>By Reference means creating an ALIAS to the original</strong>. When your Mom calls you “Pumpkin Pie” although your name is Margaret, this doesn’t suddenly give birth to a clone of yourself: you are still one, but you can be called by these two very different names.</li></ul><p>Let’s examine how Primitives and Objects behave, first when we assign them values with the <a href="https://hackernoon.com/tagged/assiognment">assignment</a> operator (=), and second when we pass them to a function as a parameter.</p><h3>1. Assigning a value with the = operator to Primitives an Objects</h3><h4>With Primitive Data Types, =operator works by value</h4><p>Consider the following code:</p><pre>var name = &quot;Carlos&quot;;<br>var firstName = name;<br>name = &quot;Carla&quot;;</pre><pre>console.log(name); // &quot;Carla&quot;<br>console.log(firstName); // &quot;Carlos&quot;</pre><p>→ <a href="https://jsbin.com/naloqarajo/edit?js,console">Try it yourself</a></p><p>The result is pretty straightforward : that’s the = operator working by value. What really happens here can be simplified as follows :</p><ul><li>A variable name is created and given the value of &quot;Carlos&quot;. JavaScript allocates a memory spot for it.</li><li>A variable firstName is created and is given a <em>copy</em> of name&#39;s value. firstName has its own memory spot and is independent of name . At this moment in the code, firstName also has a value of &quot;Carlos&quot;.</li><li>We then change the value of name to &quot;Carla&quot;. But firstName still holds its original value, because it lives in a different memory spot.</li></ul><blockquote>When working with primitives, the =operator creates a copy of the original variable. That’s what by value means.</blockquote><h4>With Objects, =operator works by reference</h4><p>Consider the following code :</p><pre>var myName = {<br>  firstName: &quot;Carlos&quot;<br>};<br>var identity = myName;<br>myName.firstName = &quot;Carla&quot;;</pre><pre>console.log(myName.firstName); // &quot;Carla&quot;<br>console.log(identity.firstName); // &quot;Carla&quot;</pre><p>→ <a href="https://jsbin.com/fujidanoma/edit?js,console">Try it yourself</a></p><p>Here the output is the same for the variables containing objects. That happens because, when dealing with objects, the =operator works by reference. What is really happening can be described as follows:</p><ul><li>A variable myName is created and is given the value of an object which has a property called firstName. firstName has the value of &quot;Carlos&quot;. JavaScript allocates a memory spot for myName and the object it contains.</li><li>A variable identity is created and is pointed to myName. <em>There is no dedicated memory space to </em><em>identity&#39;s value&#39;</em>. It only <em>points to</em> myName&#39;s value.</li><li>We change the value of myName&#39;s firstName property to &quot;Carla&quot; instead of &quot;Carlos&quot;.</li></ul><p>When we log myName.firstName it displays the new value, which is pretty straightforward. But when we log identity.firstName its <em>also</em> displays myName.firstName&#39;s new value &quot;Carla&quot;. This happens because identity.firstName only <em>points to</em> myName.firstName’s place in the memory.</p><blockquote>When working with objects, the =operator creates an alias to the original object, it doesn’t create a new object. That’s what “by reference” means.</blockquote><h3>2. Passing Primitives and Objects to a function</h3><h4>Primitive Data Types are passed to a function by value</h4><p>If you change the value of a Primitive Data Type inside a function, this change won’t affect the variable in the outer scope:</p><pre>var myName = &quot;Carlos&quot;;<br>function myNameIs(aName){<br>  aName = &quot;Carla&quot;;<br>}<br>myNameIs(myName);</pre><pre>console.log(myName); // &quot;Carlos&quot;</pre><p>→ <a href="https://jsbin.com/jiciyunaso/edit?js,console">Try it yourself</a></p><p>Even if we are changing the myName variable inside of the function myNameIs, when we print it after calling the function, it still has the value &quot;Carlos&quot;. That is because when primitive types are passed, they are passed by value.</p><p>We are passing a copy of myName: anything you do to myName inside the body of the function won&#39;t affect the myNamevariable in the global scope because you are passing a copy of myName, and not the original myName variable.</p><h4>Objects are passed to a function by reference</h4><p>When you are passing something by reference, you are passing something that points to something else, not a copy of the object. So since JavaScript passes objects by reference, when you change a property of that object within the function, the change will be reflected in the outer scope:</p><pre>var myName = {};<br>function myNameIs(aName){<br>  aName.firstName = &quot;Carla&quot;;<br>}<br>myNameIs(myName);</pre><pre>console.log(myName); // Object {firstName: &quot;Carla&quot;}</pre><p>→ <a href="https://jsbin.com/weqamuwewu/edit?js,console">Try it yourself</a></p><p>Now if I log the myName variable after having invoked the function myNameIs, it logs an object with a key of firstName with a value equal to &quot;Carla&quot;. The object did change in the global scope when we passed it to the function.</p><p>This is because when you pass an object into the function, you are not passing a copy. You are passing something that <em>points</em> to the myName object. So when you change a property of that object in the function, you are changing the property of the object in the outer scope.</p><p>But there is a subtlety you should be aware of:</p><pre>var myName = {<br>  firstName: &quot;Carla&quot;<br>};</pre><pre>function myNameIs(aName){<br>  aName = {<br>    nickName: &quot;Carlita&quot;<br>  };<br>}</pre><pre>myNameIs(myName);<br>console.log(myName); // Object {firstName: &quot;Carla&quot;}</pre><p>→ <a href="https://jsbin.com/zifayokotu/edit?js,console">Try it yourself</a></p><p>Here it prints the value of the variable myName in the outer scope and didn&#39;t add a nickName property to the object this time. Why is that ? If you look carefully, what we are doing in the function is trying to reassign the myName object a new value.</p><p>But you can’t change what myName <em>points to</em>, you can only change a <em>property</em> of myName to something else, like this:</p><pre>var myName = {<br>  firstName: &quot;Carla&quot;<br>};</pre><pre>function myNameIs(aName){<br>  aName.nickName = &quot;Carlita&quot;;<br>}</pre><pre>myNameIs(myName);<br>console.log(myName); // Object {firstName: &quot;Carla&quot;, nickName: &quot;Carlita&quot;}</pre><p>→<a href="https://jsbin.com/xicuyuneho/edit?js,console"> Try it yourself</a></p><p>Want to learn more ? Check out my other articles on the basics of JavaScript:</p><ul><li><a href="https://hackernoon.com/hoisting-in-javascript-a-quick-guide-cc4d9597bbd7"><strong>Hoisting in JavaScript: a Quick Guide</strong></a></li><li><a href="https://hackernoon.com/understand-javascript-variable-scope-with-ease-221a6d41dc43"><strong>Understand JavaScript Variable Scope with ease</strong></a></li><li><a href="https://hackernoon.com/get-your-head-around-this-73c23653b102"><strong>Get your head around “this”</strong></a></li><li><a href="https://hackernoon.com/how-to-use-javascript-closures-with-confidence-85cd1f841a6b"><strong>How to use JavaScript closures with confidence</strong></a></li><li><a href="https://hackernoon.com/a-quick-handbook-for-dates-in-javascript-7b71d0ef8e53"><strong>A Quick Handbook for Dates in JavaScript</strong></a></li><li><a href="https://medium.com/@lenafaure/work-with-javascript-arrays-like-a-boss-97207a042e42"><strong>Work with JavaScript arrays like a boss</strong></a></li></ul><p>I hope you enjoyed this explanation of “By Value” and “By Reference”.</p><p>Feel free to comment and like this article so that others can find it easily on Medium !</p><figure><a href="http://eepurl.com/dvio9L"><img alt="" src="https://cdn-images-1.medium.com/max/690/1*td_Zl-oX7vl2kIsoldqcLA.png" /></a></figure><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ed75efa1293" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/grasp-by-value-and-by-reference-in-javascript-7ed75efa1293">Grasp “By Value” and “By Reference” in JavaScript</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use JavaScript closures with confidence]]></title>
            <link>https://medium.com/hackernoon/how-to-use-javascript-closures-with-confidence-85cd1f841a6b?source=rss-d67581bfc14b------2</link>
            <guid isPermaLink="false">https://medium.com/p/85cd1f841a6b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Léna Faure]]></dc:creator>
            <pubDate>Thu, 18 May 2017 13:37:25 GMT</pubDate>
            <atom:updated>2019-05-15T12:00:54.135Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using closures will be a piece of (chocolate) cake</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJ6YpCYam_N_o_wJhyomog.jpeg" /></figure><p>From the words of <a href="https://github.com/getify/You-Dont-Know-JS/tree/master/scope%20%26%20closures">Kyle Simpson</a>,</p><blockquote>“Closure is all around you in JavaScript, you just have to recognize and embrace it.”</blockquote><p>When you write in <a href="https://hackernoon.com/tagged/javascript">JavaScript</a>, closures just happen… wether you are aware of it or not. Understanding closures to intentionally create them and leverage their power is a challenge that every JavaScript developer has to tackle; let’s give it a try with this article.</p><p>Here’s a somewhat academic definition that will help you understand and spot a closure when you see one : <strong>closure is when a function is able to remember and access the variables of the outer (enclosing) function even when that function is executing outside its scope.</strong></p><blockquote><em>Closure is when a function is able to remember and access the variables of the outer (enclosing) function even when that function is executing outside its scope.</em></blockquote><p>We will go back to the <a href="https://hackernoon.com/understand-javascript-variable-scope-with-ease-221a6d41dc43"><em>scope</em></a> concept a little later. Just know for the moment that, depending on the position of a variable in the code, some functions will have access to it and some will not.</p><p>Now about the <em>variables</em>; as you already may know, a variable has two components : a name and a value. The name “variable” makes it very clear : its value can <em>vary</em> from one moment to the next. But sometimes, we need to keep the value as it was at a certain point in time to use it later.</p><p>In JavaScript, this situation is frequently encountered when working with functions like setTimeout() and setInterval() for example.</p><h3>The for loop example</h3><p>Let’s take the example of a for loop used to display a counter, and a setTimout() function used to delay the execution of a function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f996d9dea14d3a68301bc7d20d81dd8/href">https://medium.com/media/4f996d9dea14d3a68301bc7d20d81dd8/href</a></iframe><p>Looking at this code snippet, you would normally assume that it would print the numbers 0 to 9, one per second. In fact if you run this code, you get 10 printed out ten times, at a one-second interval :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*pt--96YkrtjAM0Vu.gif" /></figure><p><em>Why is that happening ?</em></p><p>When the for loop runs and setTimeout() gets called sometime in the future (in that case, one second later in the future), the value of the variable i has already been incremented to the end of its range by the for loop.</p><p>This is a case where <em>we need to store and access the value of a variable at a given time</em>, before it is modified again. At each iteration loop, we need to “capture” the corresponding copy of i and store it for later use. The good news is that closures are going to help us do just this :<strong> create a new closured scope at each iteration of the loop</strong>.</p><p>We will get back to this example and see how to add a closure to our loop. But before diving deeper inside the workings of closures, let’s take a brief detour and review some important concepts we need to understand well to get a full grasp of closures.</p><h4>A function is also a variable</h4><p>A function is a special variable : you can reassign a value to it and pass it to another function as parameters (this is useful in writing asynchronous functions which are passed as callbacks arguments).</p><h4>The scope of a variable</h4><p>Variables that are defined outside of a function can be accessed by that function. They can be modified outside of that function as well as by the function itself.</p><p>Variables that are defined inside of a function, as well as the arguments passed to a function, are only accessible inside the function.</p><p><em>(To learn more about the scope, please refer to </em><a href="https://hackernoon.com/understand-javascript-variable-scope-with-ease-221a6d41dc43"><em>this article</em></a><em>)</em></p><h4>Passing a variable to a function</h4><p>When a variable is passed as an argument to a function, the <em>value</em> of the variable is copied inside the argument.</p><h3>Taking closures by storm</h3><p>Now that we finished our detour and got back, we are ready to tackle closures.</p><p>Let’s consider the following code :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66195c5d282ecfb41129094db9f2bceb/href">https://medium.com/media/66195c5d282ecfb41129094db9f2bceb/href</a></iframe><p>Let’s dive a little deeper into this function : what’s going on here ?</p><p>We define an argument number1 that will take the value of the variable passed to the function.</p><p>We define a <em>function inside the function</em> myFunction. In this nested function, the variable number1 is accessible because it has been defined outside of the add function, in its parent function myFunction.</p><p>We return the add function, but we are not <em>calling</em> it. What does this mean ?</p><p>The myFunction function <em>returns a function </em>: the add function. When I print myFunction to the console, it will display the return result of the function, which is <em>another function</em> (the add function) :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e40794b1399e356ea27ba2125a157f8e/href">https://medium.com/media/e40794b1399e356ea27ba2125a157f8e/href</a></iframe><p>Why is this important ? Because it means that I can assign a value to number1, pass it to myFunction, and this new value of number1 will be stored for later use, when I will be ready to finish the job and call the add function.</p><p>And here is the awesome thing about closures : <strong>you can write functions with an intermediate state that can capture data from your application, at a very specific moment in time, and you can then use this data at another, later moment in time</strong>. Using closures is like adding a “pause” button inside your function. You can go back to it later, when there has been a change in your app (a click event from the user for example), and still be able to retrieve the value of your data before this change in the application happened.</p><p>Without closures, JavaScript would simply run all the code and return the last known value of your data, with no way to go back to the moment when the data had the value you now want to use.</p><p>That’s what happened in our first for loop example : the setTimeout function kind of arrived late for the war. The battles of the for loop had already been fought and when the setTimeout cavalry arrived, the i variable had long been assigned 10, the latest value in the loop, and stayed that way until setTimeout arrived.</p><p>Still not convinced or not sure when to use a closure ? Let’s take an example and explain how closures work by baking a cake.</p><h3>Bake a cake with a closure</h3><p>We are going to use this code that uses a function to bake cakes that have different ingredients and cooking temperatures :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/392898b6d8ac0036b8e5e3be55841507/href">https://medium.com/media/392898b6d8ac0036b8e5e3be55841507/href</a></iframe><p>The ovenTemperature() function is <strong>a closure, a function inside a function</strong>, that can be called at any point in time after the bakeCake() function has been called.</p><p>Notice how we have to take two steps to get the whole log in the console ? If your run this code and never call chocolateCake() or carrotCake(), the console will only print :</p><pre>&quot;chocolate cake : add chocolate to the batter&quot;<br>&quot;carrot cake : add carrot to the batter&quot;</pre><p>You wouldn’t get any error, but the function inside the function, the closure, would not run and the completion of baking the cake would not happen.</p><p>Notice also that I can use my bakeCake() function to bake two very different cakes, each one being a separate instance of bakeCake() that will remember its own ingredient argument for later use.</p><p>Like in a real recipe, it is not enough to just add the ingredient to the batter, you also have to set the right temperature and baking time to have a perfect cake. And for that, you have to call another function inside the function. As we saw in the earlier example with the add() function, if this inner function isn’t called, the return of the outer function is simply another function, waiting for its time to be called, not a result value (yet).</p><p>Here, the bakeCake() function will not return the &quot;ready to bake&quot; line until you also call the ovenTemperature() function with the two arguments : it is on hold until called properly.</p><p>You can put the chocolate in the batter, let the batter rest, and take all the time you need to check your recipe book for the right temperature and baking time. It can be an hour later, you may have to call your mother to get advice on it, and the batter with chocolate will still be here, waiting for you to give the final instructions. In other words, anytime you will call chocolateCake(), the ingredient argument, chocolate, will still be incorporated.</p><p>So how do I call this inner function when I am ready ? I’ve called my mother, checked every recipe on the <a href="https://hackernoon.com/tagged/internet">internet</a>, now let’s finish off these cakes, once and for all.</p><p>I have created two instances of the bakeCake() function and assigned them to two different variables : chocolateCake and carrotCake.</p><p>Let’s concentrate on the chocolate cake. chocolateCake is a function, and an instance of bakeCake, with a chocolate argument. For chocolateCake to return the &quot;ready to bake&quot; sentence, I just have to call it and pass the arguments needed by the ovenTemperature() function.</p><p>This means that chocolateCake will not be fulfilled until we pass a second set of arguments for the closure to be triggered.</p><p>Here for simplicity of comprehension we first assigned bakeCake(&quot;chocolate&quot;) to a variable (chocolateCake), and then passed the second arguments to this variable, which is also a function. But if we already knew all the requirements of the recipe, we could have gone directly :</p><pre>bakeCake(&quot;chocolate&quot;)(250, 60);</pre><p>The ultimate take on this experiment, in the words of <a href="http://javascript.crockford.com/private.html">Douglas Crockford</a>, is that:</p><blockquote>“An inner function always has access to the vars and parameters of its outer function, even after the outer function has returned.”</blockquote><h3>Back to the setTimeout() inside a for loop example</h3><p>Now with all we know from the bakeCake() example, how can we modify the code from our first example to add a closure and make the function print the numbers from 0 to 9 instead of printing the number 10 ten times? ( remember 10 is the last known value of i : on the last iteration of the loop, the function logged 9 in the console, then incremented this number by 1.</p><p>Let’s have a look at this function in real time :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*so9wE7298vm_3cV0.gif" /></figure><p>Here is the code of our function :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e296012a636834c57415ea197aad5de5/href">https://medium.com/media/e296012a636834c57415ea197aad5de5/href</a></iframe><p>For comparison purposes, we added a simple console.log() for the i counter at each iteration of the loop, and a setTimeout() function that is supposed to do the same, this time at 1 second intervals.</p><p>From the image above we can easily see that that the setTimeout() function does indeed print a result at one second intervals, but the increment of i has already taken place and when setTimeout() begins to run, i has an unchanged value of 10 at each delayed iteration of the loop.</p><p><em>How are we getting out of this ?</em></p><p>Let’s apply what we have learned from using closures so far, and write a timer()function that will act as the outer function for setTimeout(), from which setTimeout() will be able to access the value of i :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3eacc134cb582aa374e1ae28fb6af262/href">https://medium.com/media/3eacc134cb582aa374e1ae28fb6af262/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*D_5l2XUsSVsANrxW.gif" /></figure><p>And… it works !</p><p>Here we declared a timer() function and wrapped the setTimeout() function inside of it. We then pass it the exact value of the counter at each iteration of the loop, hereby <strong>&quot;closing&quot; the value of </strong><strong>i inside the function at each iteration</strong>.</p><p>We could also have written :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/969c447e88f5e84fef311dca2ddabfdd/href">https://medium.com/media/969c447e88f5e84fef311dca2ddabfdd/href</a></iframe><p>where we declare an anonymous self-invoking function and pass it the argument i at each iteration of the loop.</p><p>This will print the number 0 to 9 at one second intervals, thanks to the closure we created : <strong>we captured the value of </strong><strong>i at a given iteration of the loop, we <em>closed</em> it inside a function, passed the value to </strong><strong>setTimeout() and then called the function</strong>.</p><h3>A closing word</h3><p>Closures on the front-end can help us achieve a lot of things, like <a href="http://stackoverflow.com/questions/3495679/passing-parameters-in-javascript-onclick-event">passing parameters on a click event from the user</a> or <a href="https://medium.com/@lenafaure/how-i-sort-of-got-around-the-google-maps-api-results-limit-1c673e66ef36">overcoming the google maps API results limit</a>.</p><p>On your journey to becoming an intermediate or advanced JavaScript developer, you will come across closures and now be able to spot them, hopefully use them, and understand some bugs that wouldn’t make sense otherwise.</p><p>Want to learn more ? Check out my other articles on the basics of JavaScript:</p><ul><li><a href="https://hackernoon.com/hoisting-in-javascript-a-quick-guide-cc4d9597bbd7"><strong>Hoisting in JavaScript: a Quick Guide</strong></a></li><li><a href="https://hackernoon.com/understand-javascript-variable-scope-with-ease-221a6d41dc43"><strong>Understand JavaScript Variable Scope with ease</strong></a></li><li><a href="https://hackernoon.com/get-your-head-around-this-73c23653b102"><strong>Get your head around “this”</strong></a></li><li><a href="https://hackernoon.com/grasp-by-value-and-by-reference-in-javascript-7ed75efa1293"><strong>Grasp “By Value” and “By Reference” in JavaScript</strong></a></li><li><a href="https://hackernoon.com/a-quick-handbook-for-dates-in-javascript-7b71d0ef8e53"><strong>A Quick Handbook for Dates in JavaScript</strong></a></li><li><a href="https://medium.com/@lenafaure/work-with-javascript-arrays-like-a-boss-97207a042e42"><strong>Work with JavaScript arrays like a boss</strong></a></li></ul><p>I hope you enjoyed this introduction to JavaScript closures.</p><p>Feel free to comment and like this article so that others can find it easily on Medium !</p><figure><a href="http://eepurl.com/dvio9L"><img alt="" src="https://cdn-images-1.medium.com/max/690/1*td_Zl-oX7vl2kIsoldqcLA.png" /></a></figure><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85cd1f841a6b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-to-use-javascript-closures-with-confidence-85cd1f841a6b">How to use JavaScript closures with confidence</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understand the keyword “this” in JavaScript]]></title>
            <link>https://medium.com/hackernoon/get-your-head-around-this-73c23653b102?source=rss-d67581bfc14b------2</link>
            <guid isPermaLink="false">https://medium.com/p/73c23653b102</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Léna Faure]]></dc:creator>
            <pubDate>Sun, 07 May 2017 10:51:47 GMT</pubDate>
            <atom:updated>2019-05-15T12:00:54.721Z</atom:updated>
            <content:encoded><![CDATA[<h4>The &quot;this&quot; keyword in JavaScript can be confusing. Let’s demystify it !</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FTiIwQEmhMqsqX-cVWJtHQ.jpeg" /></figure><p>In <a href="https://hackernoon.com/tagged/javascript">JavaScript</a>, the this keyword has the same use as when we use it in a plain sentence : it refers to something that we already introduced earlier.</p><p>If I say : <em>“I met Gary Vaynerchuck yesterday at a web convention. This guy is amazing.”</em>, you immediately understand that “this guy” refers to Gary Vaynerchuck.</p><p>In a similar way, when used in JavaScript, this refers to an object, and more specifically to the object that invokes the code.</p><p>Consider this example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fa99c56355197c9a11babb960a397ae/href">https://medium.com/media/9fa99c56355197c9a11babb960a397ae/href</a></iframe><p>→ <a href="https://jsbin.com/cijojefuja/edit?js,console">Try it yourself</a></p><p>We created a customer object with properties and a greetCustomer method. The method uses the keyword this to refer to the customer object.</p><p>Note that this is able to access the properties of the object (firstName and lastName). It is because <strong>not only </strong><strong>this <em>refers</em> to the </strong><strong>customer object , but it also <em>contains</em> the value of the object</strong> : it can therefore access the methods and properties of the object.</p><p>When the greetCustomer method is invoked, this inside the method automatically refers to the object that invoked the method : the customer object . But before the method was called, and this is very important to grasp, <em>this was not assigned a value</em>.</p><p>What does it mean ?</p><p>Take this function for example:</p><pre>var sayCatName = function(catName){<br>  	console.log(&quot;My cat&#39;s name is &quot; + catName);<br>};</pre><p>What is it going to print ? Well, for the moment, not much, we have <em>defined</em> the function but we don’t know the value of catName until we <em>invoke</em> the function and pass it a cat&#39;s name :</p><pre>sayCatName(&#39;Alphonse&#39;); // Prints &quot;My cat&#39;s name is Alphonse&quot;</pre><p>And that’s the exact same idea behind the this keyword : we won&#39;t know what it refers to until an object invokes a function where this is defined. In other words, the this keyword is not assigned a value until a function where it is defined is actually called.</p><p>So <strong>whenever you are trying to figure out what the </strong><strong>this keyword refers to, ask yourself the question: <em>&quot;Where is this function invoked ?&quot;</em></strong>. Not where it is defined, but where it is called.</p><blockquote>Whenever you are trying to figure out what the this keyword refers to, ask yourself the question: <em>&quot;Where is this function invoked ?&quot;</em>. Not where it is defined, but where it is called.</blockquote><p>This was a basic example, and there will be times when it will be more difficult to determine what this refers to in our code. Let&#39;s now dive into the four rules that will allow us to do so :</p><ul><li><strong>Implicit Binding</strong> (When this is inside of a declared object)</li><li><strong>Explicit Binding</strong> (When we explicitly set the value of this using call, apply or bind)</li><li><strong>The global context</strong> (When this is outside of a declared object)</li><li><strong>The </strong><strong>new keyword </strong>(When creating a new object)</li></ul><h3>1. Implicit Binding (When this is inside a declared object)</h3><p>When the keyword this is found inside of a declared object, the value of this will always be the closest parent object.</p><p>Consider our customer object with a new method whatIsMyObject:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cda4284223209da14aaf32b5ce2fada2/href">https://medium.com/media/cda4284223209da14aaf32b5ce2fada2/href</a></iframe><p><a href="https://jsbin.com/jimiyehaju/edit?js,console">→ Try it yourself</a></p><p>We find the keyword this first Inside of the function greetCustomer. The closest parent object is the customerobject, which means that the value of the this is the customerobject.</p><p>When we print this alone inside the function whatIsMyObject, whose closest parent is also the customerobject, we get the whole object printed in the console, so we are now sure that the value of this is the customer object.</p><p>This is all well, but what happens when we have a nested object ?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f3494931c53a009699f2d810733ca64/href">https://medium.com/media/4f3494931c53a009699f2d810733ca64/href</a></iframe><p><a href="https://jsbin.com/zecivoneya/edit?js,console">→ Try it yourself</a></p><p>We added a key to the customer object called address. The value of address is another object. Inside this object, we have an askAddress function that uses this to call the customer by his name.</p><p>However, this seems to be unable to access the property name of the customer object and prints <em>&quot;Dear undefined, please enter your address&quot;</em>. Have you guessed why ?</p><p>Well let’s go back to our rule that says that the value of this will always be the closest parent object : here we are in the customer object, but also inside the nested address object, which is in fact the closest parent to this when it it inside the function askAdress.</p><p>Since the address object has no property firstName, this.firstName is undefined. We can also see that the whatIsMyObject function inside the address object doesn&#39;t refer to customer anymore but to address.</p><p>So how can we fix this ? What if we need our askAddress method to return the name of the customer ? We will need to explicitely change the value of this with the call, apply or bind methods.</p><h3>2. Explicit Binding (When we explicitly set the value of this using call, apply or bind)</h3><p>Functions in JavaScript are objects, and as objects they have several methods. We use the call, apply and bind methods of a function when we want full control over what the keyword this refers to.</p><p>Let’s take the code we used in the previous example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f3494931c53a009699f2d810733ca64/href">https://medium.com/media/4f3494931c53a009699f2d810733ca64/href</a></iframe><p>Previoulsy, we were calling customer.address.askAddress, which was returning <em>&quot;Dear undefined…&quot;</em> , because the value of this inside the askAddress function refers to the address object, which does not have a firstNameproperty.</p><h3>call()</h3><p>By using the callmethod, we can change what we want the value of this to be : here we are going to change the value of this to be the customer object:</p><pre>customer.address.askAddress.call(customer); // Prints &quot;Dear John, please enter your address&quot;</pre><p><a href="https://jsbin.com/nireruvoca/edit?js,console">→ Try it yourself</a></p><p>It worked ! Note that we are not <em>invoking</em> askAddress , we just <em>attach</em> the method call onto it, so there are no parentheses after the askAddress method when we use call.</p><p>The parameter to the call method is what we want the keyword this to refer to, in this case the customer object.</p><h3>apply()</h3><p>The difference between call and apply can be seen when we have arguments to the function we want to use call or applyon.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c201a2637445fa78614833f4fba807e4/href">https://medium.com/media/c201a2637445fa78614833f4fba807e4/href</a></iframe><p>We have created a new method calculateAge, which takes two arguments currentYear and birthDate.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c76d9d3e075890d049942507fb0837b8/href">https://medium.com/media/c76d9d3e075890d049942507fb0837b8/href</a></iframe><p>→ <a href="https://jsbin.com/zakawamada/edit?js,console">Try it yourself</a></p><p>Both solutions are working, the only difference will be :</p><ul><li>Using the call function, we pass arguments separated by a comma,</li><li>Using the apply function, we pass arguments as values in an array</li></ul><h3>bind()</h3><p>bind works just like call, but instead of <em>calling</em> the function right away, it returns a function <em>definition</em>, with this set to the first parameter passed to bind().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3abd7066db24b1ea5e0388ad734cad78/href">https://medium.com/media/3abd7066db24b1ea5e0388ad734cad78/href</a></iframe><p><a href="https://jsbin.com/nuyajizuyu/edit?js,console">→ Try it yourself</a></p><p>bind allows us to explicitly set this to the object we want. It generates a copy of the calculateAge function that we stored in the variable ageOfCustomer3, but it doesn&#39;t immediately <em>call</em> the function.</p><p>We can call the function later on in the code and pass it the arguments it needs to execute. It can be extremely useful to create functions with preset arguments that will be called later, with this already set to the right object.</p><h3>3. The global context (When this is outside of a declared object)</h3><p>this is in the global context when you find it &quot;into the wild&quot;, outside of a declared object (meaning that there has not been an object defined which contains the keyword this).</p><p>In this case, its value refers to the global object, which, in the browser, corresponds to the window object.</p><p>And in fact, every variable declared in the global scope is actually attached to the window object :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7879cc2372fb134d69d3683519c18916/href">https://medium.com/media/7879cc2372fb134d69d3683519c18916/href</a></iframe><p><a href="https://jsbin.com/qiyizipujo/edit?js,console">→ Try it yourself</a></p><p>What if we find this inside a regular function call (not an object or an object&#39;s method) ? In that case, the this keyword also points at the global object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6419c3d7918a28fdac4336d26d5c1d81/href">https://medium.com/media/6419c3d7918a28fdac4336d26d5c1d81/href</a></iframe><p><a href="https://jsbin.com/zubixiluto/edit?js,console">→ Try it yourself</a></p><p>Here when I call the greetCustomer method, the nestedFunction will be invoked, and prints the global window object, even though we are inside the customer object. Why is that ?</p><p>What we have here is a regular function call inside a method, not a method of the object. Although it is written inside of the method, it is still a simple function.</p><h3>4. The new keyword</h3><p>One way of creating an object is by using the new keyword.</p><p>Consider this function Customer that defines an object:</p><pre>function Customer(firstName, lastName) {<br>  this.firstName = firstName;<br>  this.lastName = lastName;<br>}</pre><p>Inside of this function, we are defining the properties of the object with the keyword this, and they will be equal to the value passed to the function.</p><p>Hold on here, we are inside of a function; shouldn’t the value of this be the global object, as we saw earlier ?</p><p>But in this case, we are not going to make a regular function call to create a new object. Instead, we are going to use the new keyword, and the rule is that the value of this changes when you use the new keyword.</p><pre>var customer1 = new Customer(&quot;John&quot;, &quot;Smith&quot;);</pre><pre>console.log(customer1.firstName + &quot; &quot; + customer1.lastName); // Prints &quot;John Smith&quot;</pre><p><a href="https://jsbin.com/menitozemi/edit?js,console">→ Try it yourself</a></p><p>this now refers to the object that is created when the new keyword is used. We are storing that object in a variable called customer1 , that can now access the firstName and lastName properties.</p><h3>Conclusion</h3><p>To know what is the value of this inside of your code, always ask yourself the question:</p><blockquote><strong>Where is the function invoked ?</strong></blockquote><p>There are some very tricky parts to this that are reviewed in great detail in <a href="http://javascriptissexy.com/understand-javascripts-this-with-clarity-and-master-it/">this article</a> :</p><blockquote>“The this keyword is most misunderstood when we borrow a method that uses this, when we assign a method that uses this to a variable, when a function that uses this is passed as a callback function, and when thisis used inside a closure - an inner function.”</blockquote><p>You will surely often encounter some real-world problems while using native JavaScript or libraries like jQuery, and an understanding of the basic workings of this will be of great help in those cases.</p><p>Want to learn more ? Check out my other articles on the basics of JavaScript:</p><ul><li><a href="https://hackernoon.com/hoisting-in-javascript-a-quick-guide-cc4d9597bbd7"><strong>Hoisting in JavaScript: a Quick Guide</strong></a></li><li><a href="https://hackernoon.com/understand-javascript-variable-scope-with-ease-221a6d41dc43"><strong>Understand JavaScript Variable Scope with ease</strong></a></li><li><a href="https://medium.com/@lenafaure/how-to-use-javascript-closures-with-confidence-85cd1f841a6b"><strong>How to use JavaScript closures with confidence</strong></a></li><li><a href="https://hackernoon.com/grasp-by-value-and-by-reference-in-javascript-7ed75efa1293"><strong>Grasp “By Value” and “By Reference” in JavaScript</strong></a></li><li><a href="https://hackernoon.com/a-quick-handbook-for-dates-in-javascript-7b71d0ef8e53"><strong>A Quick Handbook for Dates in JavaScript</strong></a></li><li><a href="https://medium.com/@lenafaure/work-with-javascript-arrays-like-a-boss-97207a042e42"><strong>Work with JavaScript arrays like a boss</strong></a></li></ul><p>I hope you enjoyed this <a href="https://hackernoon.com/tagged/introduction">introduction</a> to the JavaScript keyword “this”.</p><p>Feel free to comment and like this article so that others can find it easily on Medium !</p><figure><a href="http://eepurl.com/dvio9L"><img alt="" src="https://cdn-images-1.medium.com/max/690/1*td_Zl-oX7vl2kIsoldqcLA.png" /></a></figure><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73c23653b102" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/get-your-head-around-this-73c23653b102">Understand the keyword “this” in JavaScript</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understand JavaScript Variable Scope with ease]]></title>
            <link>https://medium.com/hackernoon/understand-javascript-variable-scope-with-ease-221a6d41dc43?source=rss-d67581bfc14b------2</link>
            <guid isPermaLink="false">https://medium.com/p/221a6d41dc43</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Léna Faure]]></dc:creator>
            <pubDate>Sun, 30 Apr 2017 08:50:58 GMT</pubDate>
            <atom:updated>2019-05-15T12:00:55.359Z</atom:updated>
            <content:encoded><![CDATA[<h4>Because in JavaScript, the Scope is all around you</h4><p>In <a href="https://hackernoon.com/tagged/javascript">JavaScript</a>, the scope determines where your <a href="https://hackernoon.com/tagged/program">program</a> can see and use certain variables.</p><p>In other words, <strong>referring to the scope of a variable equals to answering the question : “where can we access this particular variable ?”</strong>.</p><h3>Global and Local Scope</h3><p>The scope can be twofold : global or local.</p><p><strong>Global </strong>: variables defined <em>outside</em> a function are global and accessible from anywhere in your code.</p><p><strong>Local</strong> : variables defined <em>inside</em> of a function are considered local to that function only. It can’t be accessed or used by any of your code outside that function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7w_u-h9dBxSCGQl5l3N4Rg.jpeg" /><figcaption><a href="https://unsplash.com/">https://unsplash.com/</a></figcaption></figure><p>Think of the global scope as the outer space up here beyond the earth’s atmosphere : it doesn’t belong to any country, and everything you could find there is accessible to everyone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6pLblL3RgIUVVzNQknmIzQ.jpeg" /><figcaption><a href="https://unsplash.com/">https://unsplash.com/</a></figcaption></figure><p>Now think of a local scope as the space defined within the borders of the USA . Now it’s different : everything you could find here belongs to the USA, and to the USA only.</p><p>As someone coming from the outside, you have no right to access and claim the resources you would find within these borders.</p><p>However, as someone coming from the USA, you would still have access to everything in outer space, the global scope.</p><p>The scope of a variable in Javascript works basically the same way :</p><p><strong>Variables in an inner (local) scope can’t be seen or used by an outer (global) scope, but variables defined in an outer (global) scope can be seen and used by an inner (local) scope.</strong></p><blockquote><strong>Variables in an inner (local) scope can’t be seen or used by an outer (global) scope, but variables defined in an outer (global) scope can be seen and used by an inner (local) scope.</strong></blockquote><p>Here’s an example of global and local scope :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93d6e10b0289a54861aad69dd049e94e/href">https://medium.com/media/93d6e10b0289a54861aad69dd049e94e/href</a></iframe><p>So what happened here ? We know that variables declared within a function are <em>local</em> variables and are only accessible within that function.</p><p>Inside of the sayHello function, in this local scope, greeting is equal to &quot;Hi, I am a local variable&quot;.</p><p>So when we call the function sayHello, the value of greeting is the one defined in the local scope.</p><p>However, when we simply log the greeting variable from the global scope, where we are not inside of any function, the program gets the value of the variable that we defined globally : &quot;Hi, I am a global variable&quot;.</p><p>That’s very important: <strong>when we create a function, it has its own scope, its own set of variables.</strong></p><blockquote>When we create a function, it has its own scope, its own set of variables.</blockquote><p>However, as we said before, this doesn’t mean that inside of a function we can’t access variables that are defined outside of the function :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4d4172cfc4f38a23f3d714ea646174a/href">https://medium.com/media/e4d4172cfc4f38a23f3d714ea646174a/href</a></iframe><p>What we see here is that when we define a variable <em>outside</em> of a function, we still have access to it <em>inside</em> of that function.</p><p>Basically to wrap it up:<strong> if we declare a variable outside a function, we can access it from inside a function, but the reverse is not true</strong>.</p><blockquote><strong>If we declare a variable outside a function, we can access it from inside a function, but the reverse is not true</strong></blockquote><h3>Functions Inside Functions</h3><p>But what happens if you create a function inside another function ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZKGX0UAH_MxEJUzeLexnfw.jpeg" /><figcaption><a href="https://unsplash.com/">https://unsplash.com/</a></figcaption></figure><p>Well my friend if you do that, you are actually creating <strong>two scopes</strong>, and these scopes will behave as follows :</p><p>the child function will be able to see all the variables of all the parent functions, but the parent function will never know the variables declared inside its child function.</p><p>In other words, what is called the <strong>scope chain</strong> (the path that JavaScript takes when it is looking for a variable’s existence and value) works in one direction only : from the location where it is called up to the parent functions and, finally, the global scope.</p><p>So for example if we are looking for variables located in different scopes from a function that is nested inside another function, JavaScript would do this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*aNxudUQC7cL7U_wM6OQ-eQ.png" /><figcaption>The Scope Chain</figcaption></figure><p>I am calling the function parent from the global scope, which is prompted to run the child function, which in turn is in charge of printing the 3 values of the 3 variables declared throughout different scopes.</p><p>To determine the existence and value of each of the three variables, JavaScript starts from the inside of the child function (the innermost scope being executed at the time) and goes one level up until it has either found all the variables or hit the global scope.</p><blockquote>JavaScript starts from the inside of the child function (the innermost scope being executed at the time) and goes one level up until it has either found all the variables or hit the global scope.</blockquote><p>This scope search stops once the first match is found, which means that if all three variables a, b and c had been declared inside the child function, JavaScript would have not felt the need to work its way upward and the execution would have stopped right there in the scope of the child function.</p><h3>The var Keyword</h3><p>Consider the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35ccafda263dd378685ee8e72ea7fae9/href">https://medium.com/media/35ccafda263dd378685ee8e72ea7fae9/href</a></iframe><p>Hey ?! How come myVariable &#39;s value took the value defined locally ? The global variable was overwritten by the local variable. Why ?</p><p>Notice in this example that myVariable in our sayHello() function doesn&#39;t have the var keyword as a prefix:</p><p><strong>If a local variable is used without being declared with the </strong><strong>var keyword, it becomes a global variable.</strong></p><blockquote><strong>If a local variable is used without being declared with the </strong><strong>var keyword, it becomes a global variable.</strong></blockquote><p>Following this rule, the gobal variable was reassigned a new value when the sayHello() function ran. As a result, myVariablehas a different value before and after sayHello is run.</p><p>This also means that a variable in your local scope can have the same name as a variable in your global scope: if they are both declared with the var keyword, they are in fact two distinct variables, independent from one another. By adding var before the variable inside the function, we create a <em>new</em> variable, that exists <em>only in the scope</em> of that function.</p><p>I know this can be a bit confusing; just remember :</p><blockquote>Always declare your local variables with the var keyword before using them, otherwise you will risk unfortunate behaviours of your code.</blockquote><h3>Priority of Variables Inside Functions</h3><p>If two variables with the same name are declared in the global scope and in the local scope, which one prevails ?</p><p><strong>The local variable will have priority over the global variable when you attempt to access the variable inside a function (local scope).</strong></p><p>Let’s demonstrate this :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0c6383b2e91b5a2aad7beca2ace4dff/href">https://medium.com/media/e0c6383b2e91b5a2aad7beca2ace4dff/href</a></iframe><p>The myJob variable is declared in the global scope and in the local scope of the function that is prompted to log it in the console. JavaScript&#39;s search for myJob starts right inside the function and finds it, so it stops without attempting to look in the outer scope.</p><p>Since myJob inside the function is local, it prevails over the variable with the same name in the global scope.</p><h3>The lexical scope</h3><p>Maybe you are wondering if the scope of a variable inside a function will change depending on where the function is called inside your program : if I run my function before or after declaring it, will the variable in its scope have a different value ?</p><p>The answer is no, because functions in JavaScript are <em>lexically scoped</em> : they run in the scope in which they are <strong>defined</strong>, not the scope from which they are <strong>executed</strong>.</p><blockquote>Functions in JavaScript are <em>lexically scoped</em> : they run in the scope in which they are defined, not the scope from which they are executed.</blockquote><p>It is the static structure of a program, the location of the functions and variables written by the author of the code, that determines the scope of a variable.</p><p>Let’s consider this block of code :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/830ee448dd7ce0bec8293ec36535e8cd/href">https://medium.com/media/830ee448dd7ce0bec8293ec36535e8cd/href</a></iframe><p>The value of myVariable is in both cases the value of the variable declared <em>inside</em> the function : <strong>it is truly independent of where the function is <em>run</em> and only depends of the local scope where it is <em>declared</em>.</strong></p><h3>Conclusion : How to Use the Scope ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JStY5K6qXicjcDQMcU36jw.jpeg" /><figcaption><a href="https://unsplash.com/">https://unsplash.com/</a></figcaption></figure><p>Using the local scope of functions helps prevent accidental interference between functions. For example, it saves the time-consuming effort of making sure no name is ever used for two different purposes inside the same programs.</p><p>By creating a local scope every time a new function is written,<strong> JavaScript makes it possible to consider each function as a self-enclosed universe of its own, and a way to keep the global scope clean</strong>.</p><p>Want to learn more ? Check out my other articles on the basics of JavaScript:</p><ul><li><a href="https://hackernoon.com/hoisting-in-javascript-a-quick-guide-cc4d9597bbd7"><strong>Hoisting in JavaScript: a Quick Guide</strong></a></li><li><a href="https://medium.com/@lenafaure/get-your-head-around-this-73c23653b102"><strong>Wrap your head around “this”</strong></a></li><li><a href="https://medium.com/@lenafaure/how-to-use-javascript-closures-with-confidence-85cd1f841a6b"><strong>How to use JavaScript closures with confidence</strong></a></li><li><a href="https://hackernoon.com/grasp-by-value-and-by-reference-in-javascript-7ed75efa1293"><strong>Grasp “By Value” and “By Reference” in JavaScript</strong></a></li><li><a href="https://hackernoon.com/a-quick-handbook-for-dates-in-javascript-7b71d0ef8e53"><strong>A Quick Handbook for Dates in JavaScript</strong></a></li><li><a href="https://medium.com/@lenafaure/work-with-javascript-arrays-like-a-boss-97207a042e42"><strong>Work with JavaScript arrays like a boss</strong></a></li></ul><p>I hope you enjoyed this introduction to the JavaScript Scope.</p><p>Feel free to comment and like this article so that others can find it easily on Medium !</p><figure><a href="http://eepurl.com/dvio9L"><img alt="" src="https://cdn-images-1.medium.com/max/690/1*td_Zl-oX7vl2kIsoldqcLA.png" /></a></figure><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=221a6d41dc43" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/understand-javascript-variable-scope-with-ease-221a6d41dc43">Understand JavaScript Variable Scope with ease</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hoisting in JavaScript: a Quick Guide]]></title>
            <link>https://medium.com/hackernoon/hoisting-in-javascript-a-quick-guide-cc4d9597bbd7?source=rss-d67581bfc14b------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc4d9597bbd7</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Léna Faure]]></dc:creator>
            <pubDate>Sun, 23 Apr 2017 09:59:50 GMT</pubDate>
            <atom:updated>2019-05-15T12:00:56.904Z</atom:updated>
            <content:encoded><![CDATA[<h4>A beginner-friendly overview of the hoisting concept</h4><p><strong>Hoisting</strong> in <a href="https://hackernoon.com/tagged/javascript">JavaScript</a> means that <strong>variable and function declarations are moved to the top of their containing </strong><a href="https://medium.com/@lenafaure/understand-javascript-variable-scope-with-ease-221a6d41dc43"><strong>scope</strong></a>.</p><p>What does that translate to in my code?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T8xIFtPB1TG2gaWm9PgO_A.jpeg" /><figcaption><a href="https://unsplash.com/">https://unsplash.com/</a></figcaption></figure><h3>The Declaration Comes Before the Assignment</h3><p>Let’s consider the following snippet of code to understand how hoisting works :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad5aacd1c4ad74b1ceb370f31443ae57/href">https://medium.com/media/ad5aacd1c4ad74b1ceb370f31443ae57/href</a></iframe><p>Maybe you expected the console.log to print undefined, since the var statement (the declaration ) comes after rockStar = “Mick Jagger”(the assignment ). We assigned a value to the rockStar variable <em>before</em> it was created in the code.</p><p>After all it is logical to think that all the lines of code written in a JavaScript program are read, interpreted, and executed from top to bottom. There is a truth to that assumption, but the behaviour we just demonstrated tells us otherwise.</p><p>In real fact, just before the code is executed, it goes through a compiler : during this phase called <em>lexing,</em> <a href="https://medium.com/@lenafaure/understand-javascript-variable-scope-with-ease-221a6d41dc43">scope</a> gets defined and the <strong>variable and function declarations are moved to the top of their scope</strong>. If they are defined inside a <a href="https://hackernoon.com/tagged/function">function</a>, they are moved to the top of this function, and if they are outside a function, to the top of the global scope.</p><p>Consider this other piece of code :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f04e93d25edff78aa7af6924f11a3bb/href">https://medium.com/media/8f04e93d25edff78aa7af6924f11a3bb/href</a></iframe><p>This time, although we have the rockStar variable declared and assigned, we get an undefined response when we try to print the variable. Why is that ?</p><p>The best way to get your head around this is to remember that <strong>all declarations are processed first</strong>, and this is equally true for variables and functions.</p><blockquote><strong>All declarations are processed first</strong>, and this is equally true for variables and functions.</blockquote><p>Let’s decode what it means by reading the code just as JavaScript does.</p><p>When you see var rockStar = “Mick Jagger”, you see it as one statement, but JavaScript sees it otherwise. It actually interprets it as two distinct statements:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9a79da803136f06c91c47b45d77f0d8/href">https://medium.com/media/e9a79da803136f06c91c47b45d77f0d8/href</a></iframe><p>In our example, JavaScript first interprets the code, sees that the rockStar variable exists and moves it to the top of the scope: this is what is called <strong>hoisting</strong>.</p><p>But the second statement, the assignment, is <strong>left in place</strong>. Then, the code is executed by JavaScript as if it were written like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64cc714d67aa6af14c49cf2b69ad58bc/href">https://medium.com/media/64cc714d67aa6af14c49cf2b69ad58bc/href</a></iframe><p>In other words, <strong>the declaration comes before the assignment</strong>: only variable and function declarations are hoisted, while the assignments are left in place, just where they were written in the code.</p><blockquote>T<strong>he declaration comes before the assignment</strong>: only variable and function declarations are hoisted, while the assignments are left in place, just where they were written in the code.</blockquote><h3>Function Declarations Are Hoisted, but Function Expressions Are Not</h3><p>We have seen examples of <em>variable</em> hoisting, now let’s focus on the behavior of <em>functions</em> .</p><p>See the following piece of code :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/881e970177beba3dbef1d0b1889d7735/href">https://medium.com/media/881e970177beba3dbef1d0b1889d7735/href</a></iframe><p>From what we understand now of hoisting, how can we rewrite this code as if it were JavaScript interpreting it ?</p><p>First keep in mind that <strong>hoisting is per-scope</strong>, and that here the scope of the name variable is the <em>local scope</em> inside of the function movieStar. The variable declaration will then be hoisted to <strong>the top of the function, not of the global scope.</strong></p><p>However, we also <em>declared</em> the movieStar function in the <em>global scope</em>, and hoisting works the same for variable and function declarations: our function declaration will be moved to the top, before the<em> execution</em> of the function.</p><p>The code will be interpreted by JavaScript as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/521733d63a82aa28e52bb4df72138347/href">https://medium.com/media/521733d63a82aa28e52bb4df72138347/href</a></iframe><p>In this example, the movieStar function call works because the function declaration is hoisted, and interpreted as being declared <em>before</em> it was called.</p><p>Let’s take another example :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41785ec094707e5ace48660cd1bed46c/href">https://medium.com/media/41785ec094707e5ace48660cd1bed46c/href</a></iframe><p>What happened here? The function I assigned to the variable movieStar, a process that is called <em>function expression</em>, is not hoisted this time : when I call the function, JavaScript throws a TypeError.</p><p>That is because functions that are assigned to variables are not hoisted.</p><blockquote>Functions that are assigned to variables are not hoisted.</blockquote><p>As a demonstration, if I now write the code as follows it is now printing the expected result :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ed5553e7e48372a316dc78c32aaf7c4/href">https://medium.com/media/3ed5553e7e48372a316dc78c32aaf7c4/href</a></iframe><h3>Functions Before Variables</h3><p>We now know that both function declarations and variable declarations are hoisted. But there is another thing to be wary of: <strong>functions are hoisted first, and then variables.</strong></p><blockquote><strong>Functions are hoisted first, and then variables.</strong></blockquote><p>Consider this code where a variable and a function are declared with the same name:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba5874621646d9f381d16bf9851428d2/href">https://medium.com/media/ba5874621646d9f381d16bf9851428d2/href</a></iframe><p>The function has been hoisted before the variable, so when I print the value of businessStar it outputs the function itself.</p><p>And another example where the variable is assigned a value :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a93d3446baaa9a5293a355e3e460397a/href">https://medium.com/media/a93d3446baaa9a5293a355e3e460397a/href</a></iframe><p>This time the output is the value of the variable, because the variable has been assigned a value, which overrides the function declaration. If you now try to call the function businessStar(), you will get a TypeError: that’s because businessStar has been assigned the string “Gary Vaynerchuck” and is no longer a function.</p><h3>Conclusion</h3><p><strong>Hoisting is Javascript’s default behavior of moving declarations to the top.</strong></p><p>Rather than being available right after their declaration, variables and functions might actually be available beforehand in the code, which might lead to certain behaviors that you wouldn’t expect if you knew nothing about hoisting.</p><p>That is why as a rule, it is important to make sure, as often as you can, that you:</p><p>→ <strong>Declare all of your variables at the top of their scope</strong> (at the top of the global scope or at the top of the function scope)</p><p>→ Make sure you <strong>put all your functions, if you can, also at the top of their scope</strong>.</p><p>Want to learn more about JavaScript basics? Check out my other articles:</p><ul><li><a href="https://medium.com/@lenafaure/understand-javascript-variable-scope-with-ease-221a6d41dc43"><strong>Understand JavaScript Variable Scope with ease</strong></a></li><li><a href="https://medium.com/@lenafaure/get-your-head-around-this-73c23653b102"><strong>Wrap your head around “this”</strong></a></li><li><a href="https://medium.com/@lenafaure/how-to-use-javascript-closures-with-confidence-85cd1f841a6b"><strong>How to use JavaScript closures with confidence</strong></a></li><li><a href="https://hackernoon.com/grasp-by-value-and-by-reference-in-javascript-7ed75efa1293"><strong>Grasp “By Value” and “By Reference” in JavaScript</strong></a></li><li><a href="https://hackernoon.com/a-quick-handbook-for-dates-in-javascript-7b71d0ef8e53"><strong>A Quick Handbook for Dates in JavaScript</strong></a></li><li><a href="https://medium.com/@lenafaure/work-with-javascript-arrays-like-a-boss-97207a042e42"><strong>Work with JavaScript arrays like a boss</strong></a></li></ul><p>I hope you enjoyed this introduction to JavaScript Hoisting.</p><p>Feel free to comment and like this article so that others can find it easily on Medium !</p><figure><a href="http://eepurl.com/dvio9L"><img alt="" src="https://cdn-images-1.medium.com/max/690/1*td_Zl-oX7vl2kIsoldqcLA.png" /></a></figure><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc4d9597bbd7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/hoisting-in-javascript-a-quick-guide-cc4d9597bbd7">Hoisting in JavaScript: a Quick Guide</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>