<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Carl Anderson</title>
    <description>The latest articles on DEV Community by Carl Anderson (@canderson93).</description>
    <link>https://dev.to/canderson93</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F111146%2F04a0e90c-0e8a-486c-a0de-792c99f86037.jpeg</url>
      <title>DEV Community: Carl Anderson</title>
      <link>https://dev.to/canderson93</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/canderson93"/>
    <language>en</language>
    <item>
      <title>Break out of Tutorial Hell - What to Do When You're Going Nowhere</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Mon, 26 Jun 2023 09:18:44 +0000</pubDate>
      <link>https://dev.to/canderson93/break-out-of-tutorial-hell-what-to-do-when-youre-going-nowhere-34gf</link>
      <guid>https://dev.to/canderson93/break-out-of-tutorial-hell-what-to-do-when-youre-going-nowhere-34gf</guid>
      <description>&lt;p&gt;When you first start learning JavaScript, there is a clear path for you to follow.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Do an online course&lt;/li&gt;
&lt;li&gt;Read Detailed JavaScript Book / Course (e.g. You Don't Know JS)&lt;/li&gt;
&lt;li&gt;Follow a To-Do App Tutorial&lt;/li&gt;
&lt;li&gt;Start your own project&lt;/li&gt;
&lt;li&gt;Profit&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This path makes sense - The courses, books, and tutorials will teach you all you need to know about writing JavaScript. You even write an actual app!&lt;/p&gt;

&lt;p&gt;Surely if you follow this path, you'll reach the pot of gold at the end.&lt;/p&gt;

&lt;p&gt;You start dedicating your evenings to this path, and after several months, and hundreds of hours of painful struggle and work, you're finally ready to set out on your own.&lt;/p&gt;

&lt;p&gt;You fire up a text editor, ready to code your great idea - but you have no idea how to code. All the knowledge is in your head, but when it comes to how to string it all together, nothing comes.&lt;/p&gt;

&lt;p&gt;What went wrong? You did the work. It all made sense in the tutorials.&lt;/p&gt;

&lt;p&gt;Maybe you started too soon? Perhaps you need to spend more time doing courses? You struggled with generators, after all. You definitely have more to learn. You pick up another course...&lt;/p&gt;

&lt;p&gt;You have now entered what is affectionately known as &lt;em&gt;tutorial hell&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why courses don't work
&lt;/h2&gt;

&lt;p&gt;Okay, courses &lt;em&gt;do&lt;/em&gt; work, but lots of JavaScript courses only teach you half of what you need to know.&lt;/p&gt;

&lt;p&gt;Courses and books teach you the separate building blocks of JavaScript - and a lot of them will teach you &lt;em&gt;all&lt;/em&gt; of the building blocks, regardless of how useful they are.&lt;/p&gt;

&lt;p&gt;Courses focus on &lt;em&gt;reference material&lt;/em&gt;. The big secret of JavaScript (and coding in general) is that you will &lt;em&gt;always&lt;/em&gt; have access to reference material. You can learn about new pieces of JavaScript when you're faced with a problem that needs it.&lt;/p&gt;

&lt;p&gt;Far more important than learning and memorizing everything there is to know about JavaScript developing an &lt;em&gt;instinct&lt;/em&gt; for how pieces are used and fit together.&lt;/p&gt;

&lt;p&gt;You need to build up the &lt;em&gt;skill&lt;/em&gt; part of coding.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you should do instead
&lt;/h2&gt;

&lt;p&gt;It seems really stupid to say this, but you need to code on your own.&lt;/p&gt;

&lt;p&gt;It sounds stupid because this is &lt;em&gt;exactly&lt;/em&gt; what you have difficulty doing, and why you're going back for more tutorial hell.&lt;/p&gt;

&lt;p&gt;The trap you (and most beginners) have actually fallen into is that you've picked a project that is &lt;em&gt;far&lt;/em&gt; too difficult for your current ability.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;You need to start with a tiny project that is solely to help you learn.&lt;/a&gt; These practice projects differ from regular projects in several key ways.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It should have one clear goal&lt;/li&gt;
&lt;li&gt;It should be &lt;em&gt;small&lt;/em&gt; (even smaller than what you're thinking)&lt;/li&gt;
&lt;li&gt;You should be prepared to throw it out at the end&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I think the part worth highlighting here is that a practice project doesn't have to be &lt;em&gt;useful&lt;/em&gt; or even &lt;em&gt;good&lt;/em&gt;. In fact, it's better if it's not.&lt;/p&gt;

&lt;p&gt;I'm a fan of pointless projects when practicing. It can provide fun and novel ways to learn about parts of JavaScript while highlighting their limits in ways that may take much longer to discover if you solely explore through pragmatic projects.&lt;/p&gt;

&lt;p&gt;You'd be surprised at what you can learn by making a button chase a user's mouse around the page... or run away from it.&lt;/p&gt;

&lt;p&gt;Set a small, achievable aim, and then commit whatever coding crimes you need to get there.&lt;/p&gt;

&lt;p&gt;Right now, it's more important that you're able to code &lt;em&gt;anything.&lt;/em&gt; You're building a muscle. It will take time and consistency to grow.&lt;/p&gt;

&lt;p&gt;You'll get there one day. For now, &lt;em&gt;do what you can do&lt;/em&gt;.&lt;/p&gt;




&lt;p&gt;Are you stuck on JavaScript Tutorials? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://carlanderson.xyz/javascript-for-you/"&gt;Download my ebook on how to succeed as a self-taught JavaScript Developer, and how to find projects that you'll actually finish.&lt;/a&gt; &lt;/p&gt;

</description>
      <category>basics</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>No, People Aren't Learning to Code in 3 Months</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Thu, 22 Jun 2023 11:07:33 +0000</pubDate>
      <link>https://dev.to/canderson93/no-people-arent-learning-to-code-in-3-months-1l1o</link>
      <guid>https://dev.to/canderson93/no-people-arent-learning-to-code-in-3-months-1l1o</guid>
      <description>&lt;p&gt;At the start of your programming journey, it's natural to wonder how long you need before you're up to scratch and ready to strike it rich in the big, wide world as a bonafide &lt;em&gt;programmer&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;After all, after you've spent 1 month, 3 months, or a year on your journey, &lt;a href="https://carlanderson.xyz/how-to-write-javascript-when-you-dont-know-where-to-begin/"&gt;it can feel like you aren't making much progress&lt;/a&gt;. It's natural to want to compare yourself to others and see where you &lt;em&gt;should&lt;/em&gt; be on your journey.&lt;/p&gt;

&lt;p&gt;A quick Google would suggest the magic number to learn programming is 3 months. This is backed up by stories online about hot-shots who buckled down, ignored their children, gave up their entire lives, and programmed for 24 hours a day.&lt;/p&gt;

&lt;p&gt;If you've been programming longer than that, it's easy to feel like you're falling behind, you're not cut out for programming, or you're just not &lt;em&gt;hardcore&lt;/em&gt; enough in your approach.&lt;/p&gt;

&lt;p&gt;Except these stories have a gaping hole they never address: When have you &lt;em&gt;finished&lt;/em&gt; learning programming?&lt;/p&gt;

&lt;p&gt;As a question, it has no answer. You &lt;em&gt;never&lt;/em&gt; finish learning programming, and that's okay. It's an endlessly complex world with amazing breadth, depth, and nuance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://carlanderson.xyz/how-to-self-teach-javascript/"&gt;Programming is a skill&lt;/a&gt;, so when I hear someone say they "learned" it in a month, I treat it with the same skepticism as if someone has confidently walked up to me claiming they learned to paint or French.&lt;/p&gt;

&lt;p&gt;I'm sure they made amazing progress in that time, but take these stories with less a grain and more a boulder of salt. They're more likely to be click-bait or a victim of Dunning-Kreuger than a legitimate story that you can learn from.&lt;/p&gt;

&lt;p&gt;If you've spent 3 months, or 6 months, or 10 years programming, and don't feel like you've learned how to program, &lt;em&gt;you're completely right&lt;/em&gt;. There is &lt;em&gt;always&lt;/em&gt; more to learn, so the best path to success is consistent, sustainable growth.&lt;/p&gt;

&lt;p&gt;Have faith in yourself. You're building a muscle. It takes time, and it can be very difficult to notice a difference from one day to the next. Sometimes, it's worth looking back to appreciate how far you've come.&lt;/p&gt;

&lt;p&gt;When I first started programming, I'd look back on code that I'd written only a few months before, and be shocked by how &lt;em&gt;bad&lt;/em&gt; it was compared to what I could do now.&lt;/p&gt;

&lt;p&gt;You're building a muscle. The most important thing is that you keep at it.&lt;/p&gt;




&lt;p&gt;Are you stuck on JavaScript Tutorials? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://carlanderson.xyz/javascript-for-you/"&gt;Download my ebook on how to succeed as a self-taught JavaScript Developer, and how to find projects that you'll actually finish.&lt;/a&gt; &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>general</category>
    </item>
    <item>
      <title>3 Methods to Actually Remember What You Learn in Coding Tutorials</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Wed, 30 Sep 2020 07:16:00 +0000</pubDate>
      <link>https://dev.to/canderson93/3-methods-to-actually-remember-what-you-learn-in-coding-tutorials-j98</link>
      <guid>https://dev.to/canderson93/3-methods-to-actually-remember-what-you-learn-in-coding-tutorials-j98</guid>
      <description>&lt;p&gt;When you first deal with a new topic, coding tutorials are great. Rather than continually grasping at straws and struggling your way through a project, the instructor conveniently shortcuts all this pain - all you have to do is follow along.&lt;/p&gt;

&lt;p&gt;After several hours of painstaking copying, you have a working app - an app that &lt;em&gt;you&lt;/em&gt; built... right? Something to be proud of!&lt;/p&gt;

&lt;p&gt;But then the thought creeps in... &lt;em&gt;did&lt;/em&gt; you build it?&lt;/p&gt;

&lt;p&gt;You couldn't do it again (at least on your own). You have &lt;em&gt;no idea&lt;/em&gt; how it was built. After all that work, have you really learned anything?...&lt;/p&gt;

&lt;p&gt;Let's be honest: you probably didn't learn much - but there &lt;em&gt;is&lt;/em&gt; gold in those tutorials. &lt;a href="https://dev.to/canderson93/how-to-get-past-javascript-tutorials-copy-paste-3236"&gt;I've espoused the benefits of copying people&lt;/a&gt; to learn code, and that's what you've just been doing.&lt;/p&gt;

&lt;p&gt;The reason nothing is sticking is that when you're busy copying the instructor, there's no space to &lt;em&gt;engage&lt;/em&gt; with the content. It's not your fault, that's just the reality of being human.&lt;/p&gt;

&lt;p&gt;The real value is in what you do &lt;em&gt;after&lt;/em&gt; the tutorial.&lt;/p&gt;

&lt;p&gt;To make the content stick, you need to spend some time working with the code. Below are three effective strategies about how to do that:&lt;/p&gt;

&lt;h2&gt;
  
  
  #3: Refactor the code
&lt;/h2&gt;

&lt;p&gt;This is the most direct way of engaging with the tutorial content - go through the code and look for ways to change it.&lt;/p&gt;

&lt;p&gt;The questions you want to ask yourself are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is there some other way of structuring the code? (Different functions, classes, etc.)&lt;/li&gt;
&lt;li&gt;Are there better names for things?&lt;/li&gt;
&lt;li&gt;Are there any other language features I could use to replace this? (Arrow functions, Ternary statements, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the sake of learning, these changes &lt;em&gt;do not&lt;/em&gt; need to be improvements - you're only trying to engage with the code. In fact, if you can't think of a way to improve the code, look for ways to make it worse (while making sure it still works).&lt;/p&gt;

&lt;p&gt;This approach is the best for learning how the tutorial code works and has the lowest barrier for entry. It is also the easiest (but least effective) of these methods, as it doesn't require you to solve many new problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  #2: Change, or add a new feature
&lt;/h2&gt;

&lt;p&gt;For my money, this is my favourite way of learning from a tutorial. Take the code you have, and &lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;use it as the basis for a practice project&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In a todo-list app (because there's no shortage of tutorials for those...), you could:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add due dates for tasks&lt;/li&gt;
&lt;li&gt;Add sub-tasks&lt;/li&gt;
&lt;li&gt;Add comments to tasks&lt;/li&gt;
&lt;li&gt;Add a "Clear all" button&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of these are valuable opportunities to practice the concepts you've learned and to engage with the tutorial.&lt;/p&gt;

&lt;p&gt;This approach is best for practising building features (and projects) from scratch and is the approach I'd recommend most of the time.&lt;/p&gt;

&lt;p&gt;The downside is you may not spend much time directly working on what the tutorial was trying to teach (but you'll still learn plenty!).&lt;/p&gt;

&lt;h2&gt;
  
  
  #1: Create a similar (but different) project
&lt;/h2&gt;

&lt;p&gt;Of the methods I've outlined, this is probably the most difficult to get right, since it's hard to find the correct balance. Still, if you get it right, it can be an effective approach.&lt;/p&gt;

&lt;p&gt;The goal is to create a project that is different from the tutorial but is similar enough that you're able to use the tutorial to help you.&lt;/p&gt;

&lt;p&gt;For instance, you might use a Todo app tutorial to create a Notetaking or a Flash Card app.&lt;/p&gt;

&lt;p&gt;This approach is the best way to practice the core principles that the tutorial is trying to teach. You'll continuously be readdressing and changing things to fit your new project.&lt;/p&gt;

&lt;p&gt;The downside, as I said, is that it's challenging to strike the correct balance of "similar but different". It's easy to accidentally bite off more than you can chew.&lt;/p&gt;




&lt;p&gt;Are you stuck on JavaScript Tutorials? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://carlanderson.xyz/javascript-for-you/"&gt;Download my ebook on how to succeed as a self-taught JavaScript Developer, and how to find projects that you'll actually finish.&lt;/a&gt; &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Danger of Specializing Too Early</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Mon, 21 Sep 2020 10:24:36 +0000</pubDate>
      <link>https://dev.to/canderson93/the-danger-of-specializing-too-early-32ce</link>
      <guid>https://dev.to/canderson93/the-danger-of-specializing-too-early-32ce</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;I want to become a Full-stack dev, but I'm not very good at Front-end. Should I just become a back-end dev?&lt;br&gt;&lt;br&gt;
- A total beginner&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When you're learning to code, you're working with a goal in mind. You're not trying to learn to code, you're trying to &lt;em&gt;become a developer&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Maybe you're more specific than that - you want to be a &lt;em&gt;front-end&lt;/em&gt; or a &lt;em&gt;full-stack&lt;/em&gt; developer. Perhaps you've taken it that step further and decided to become a &lt;em&gt;React&lt;/em&gt; developer.&lt;/p&gt;

&lt;p&gt;This approach can work wonders in your later career. However, if you're still a junior (or pre-junior), it has two significant flaws:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You should learn skills outside of your specialisation. Learning a broad range of things makes learning new skills easier. If you box yourself in, you'll slow your growth.&lt;/li&gt;
&lt;li&gt;As a Junior, your experience with particular technologies isn't nearly as important to employers as your general programming experience.*&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;*Take this with a grain of salt. There are no rules when it comes to hiring, so anything is possible. I'm just trying to make things easier for you.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ideally, you would refrain from specialising until several years into your career. I can appreciate the reality isn't that simple, and that it's easier if you work towards one of these specialisations from the beginning.&lt;/p&gt;

&lt;p&gt;As a compromise, what I want you to do is to find something &lt;em&gt;adjacent&lt;/em&gt; to what you're learning, and make that your next project.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you're consuming an API, can you create your own endpoints with Express and Node?&lt;/li&gt;
&lt;li&gt;If you're learning React/Vue, can you learn to serve the files from a web server?&lt;/li&gt;
&lt;li&gt;Find out what a browser does when it fetches a webpage.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Be curious&lt;/em&gt;. &lt;a href="https://carlanderson.xyz/how-to-find-ideas-for-practice-projects/"&gt;Work on a range of projects&lt;/a&gt;. Your future self will thank you.&lt;/p&gt;




&lt;p&gt;Are you stuck on JavaScript Tutorials? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://carlanderson.xyz/javascript-for-you/"&gt;Download my ebook on how to succeed as a self-taught JavaScript Developer, and how to find projects that you'll actually finish.&lt;/a&gt; &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to self-teach JavaScript</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Thu, 02 Jan 2020 11:04:34 +0000</pubDate>
      <link>https://dev.to/canderson93/how-to-self-teach-javascript-1oi</link>
      <guid>https://dev.to/canderson93/how-to-self-teach-javascript-1oi</guid>
      <description>&lt;p&gt;There's no denying that self-teaching JavaScript is difficult - although you have the benefit of always working on areas that interest you, it can be difficult to find direction in your learning.&lt;/p&gt;

&lt;p&gt;You're continually asking yourself: are you're doing the right thing? Is there something important you're missing? What are you meant to do next?&lt;/p&gt;

&lt;p&gt;Not all learning methods are equal: the time you spend glancing over yet-another explanation of prototypal inheritance (that you still don't understand) isn't as beneficial as when you're 20 chrome tabs into solving an inheritance problem.&lt;/p&gt;

&lt;p&gt;If you're looking to make the most of your time, there's a simple cycle that you should be underpinning your learning:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write, Research, Repeat&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The key takeaway here is that your entire learning path should be driven by &lt;em&gt;writing code&lt;/em&gt;. It's a skill you have to develop, so there's no substitute for practice. The trick is &lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;finding a constant stream of ideas&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The ultimate process is straightforward, however. Write code until you get stuck, and then research your problem until you get unstuck. Over time, you'll need to research less and less.&lt;/p&gt;




&lt;p&gt;Of course, if you can't write &lt;em&gt;any&lt;/em&gt; code, then this advice isn't useful to you, so I've divided up this strategy into various learning stages to give you a more granular approach.&lt;/p&gt;

&lt;p&gt;You have three phases of learning, where the strategy differs slightly:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduction Phase&lt;/li&gt;
&lt;li&gt;Growth Phase&lt;/li&gt;
&lt;li&gt;Honing Phase&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Introduction Phase
&lt;/h3&gt;

&lt;p&gt;This phase is the simplest to grasp - you don't know anything. The best thing to do is to take a course that introduces you to the basics of JavaScript. Most people do an entire, in-depth course during this phase – after all, more is better right?&lt;/p&gt;

&lt;p&gt;No, not at this stage.&lt;/p&gt;

&lt;p&gt;The challenge most people have with the introduction phase is that they try to learn &lt;em&gt;far too much&lt;/em&gt; before attempting to apply their knowledge. They try to run before they can walk.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/canderson93/can-you-actually-learn-javascript-from-an-online-course-5eag"&gt;Courses will teach you a language, but they won't teach you how to build software&lt;/a&gt; – that's something that you can only learn from practising. You want to keep the period where you are &lt;em&gt;only&lt;/em&gt; working from a course as short as possible.&lt;/p&gt;

&lt;p&gt;In short, you want to learn absolute basics. I recommend completing the &lt;a href="https://www.freecodecamp.org/learn" rel="noopener noreferrer"&gt;Basic JavaScript section of FreeCodeCamp&lt;/a&gt;. It covers all the core building blocks you'll need to work on your own, then you can come back.&lt;/p&gt;

&lt;h3&gt;
  
  
  Growth Phase
&lt;/h3&gt;

&lt;p&gt;This phase is the point where you have enough knowledge to write code, but everything's clunky, and you're still missing significant amounts of knowledge.&lt;/p&gt;

&lt;p&gt;Initially, I recommend you completely stop your course for a while, and spend some time creating several &lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;practice projects&lt;/a&gt; to solidify what you learned during the introduction phase.&lt;/p&gt;

&lt;p&gt;When you're more confident in the basics, you should re-incorporate your course back into your learning. Doing a section in between projects is a good approach.&lt;/p&gt;

&lt;p&gt;When you've finished your course, it's a good chance to stretch yourself and try new things. Experiment, and work on the areas that interest you: Frameworks, CSS drawings, WebGL, Node. Have fun with it. It's all valuable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Honing Phase
&lt;/h3&gt;

&lt;p&gt;This phase isn't clear-cut like the other two. The honing phase is an extension of the growth phase, but we start working on more ambitious projects. Chances are you are &lt;em&gt;still&lt;/em&gt; missing significant amounts of knowledge, but coding is comfortable now.&lt;/p&gt;

&lt;p&gt;You're ready to start the honing phase when you aren't lost when working on code. You're able to imagine your own solutions to problems (even if you have to google the specifics). &lt;a href="https://dev.to/canderson93/how-to-write-javascript-when-you-don-t-know-where-to-begin-5f3f"&gt;This article might help you.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the time to practice softer aspects of programming, like the code quality and structure. Start learning best-practices, like testing, commenting your code, and (if necessary) writing docs.&lt;/p&gt;

&lt;p&gt;You can now also assemble and refine your portfolio, and use it to apply for Junior roles. It can take a long time, though, so I wouldn't make it a priority. You can also start on interview prep through sites like &lt;a href="https://www.hackerrank.com/" rel="noopener noreferrer"&gt;HackerRank&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Although it sounds cheesy, the most critical part of this entire process is to make sure &lt;em&gt;you're having fun&lt;/em&gt;. Learning to code is a slow process, and it's going to be much easier to keep your motivation if you're enjoying yourself.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1212372164520955904-487" src="https://platform.twitter.com/embed/Tweet.html?id=1212372164520955904"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1212372164520955904-487');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1212372164520955904&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;I've linked this article multiple times already, but I strongly recommend you &lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;check out this guide on choosing ideas for practice projects&lt;/a&gt;. Get out there and &lt;em&gt;write. some. damn. code.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://pages.convertkit.com/9f030a68c9/cd303b3d7b" rel="noopener noreferrer"&gt;Are you stuck on JavaScript Tutorials? Sign up to my newsletter for more helpful articles to get you moving again&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>When Are You Ready to Freelance as a Front-End Developer?</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Thu, 05 Dec 2019 12:45:22 +0000</pubDate>
      <link>https://dev.to/canderson93/when-are-you-ready-to-freelance-as-a-front-end-developer-2koa</link>
      <guid>https://dev.to/canderson93/when-are-you-ready-to-freelance-as-a-front-end-developer-2koa</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;When can I take a full front-end web project and start working as a freelancer, and how much knowledge do I need?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A newbie developer asked this in the JavaScript Facebook group – and it's a good question. After all, when you've been grinding out several months of online courses, a big question is &lt;em&gt;when do I start getting paid for this?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Many of the responses from other beginners were suggesting new technologies to learn or concepts you need to know, but the answer is much more straightforward:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You're ready to freelance when you can find people to pay you for your work.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Your development skills, while helpful for landing contracts, are secondary to your ability to sell yourself to clients, close deals, and build a successful sales funnel. As long as you can repeatedly find clients, you're able to freelance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Should you freelance?
&lt;/h2&gt;

&lt;p&gt;The thing is, as a freelancer, you're a small business. It comes with a lot of extra non-development work, like marketing yourself, negotiating contracts, creating invoices, and doing your taxes.&lt;/p&gt;

&lt;p&gt;Take a moment to think about your &lt;em&gt;reasons&lt;/em&gt; for wanting to freelance. Almost any reason will do, so long as you acknowledge that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Freelancing is a significant time investment&lt;/li&gt;
&lt;li&gt;Becoming a freelancer isn't easier than finding a job&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You'll also want to check that your current situation can survive the instability that freelancing brings. It's not uncommon to hit patches where you aren't getting paid for several months at a time, which may be a killer if you're pay-check to pay-check.&lt;/p&gt;

&lt;p&gt;Once you've decided that freelancing is for you, I highly recommend checking out &lt;a href="https://doubleyourfreelancing.com/category/start-freelancing/"&gt;Brennan Dunn's Double Your Freelancing&lt;/a&gt; - it has excellent articles for freelancers of all levels. It will get you started on the right foot.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://pages.convertkit.com/9f030a68c9/cd303b3d7b"&gt;Are you stuck on JavaScript Tutorials? Sign up to my newsletter for more helpful articles to get you moving again&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
    </item>
    <item>
      <title>How to Get Past JavaScript Tutorials: Copy &amp; Paste</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Tue, 12 Nov 2019 10:24:00 +0000</pubDate>
      <link>https://dev.to/canderson93/how-to-get-past-javascript-tutorials-copy-paste-3236</link>
      <guid>https://dev.to/canderson93/how-to-get-past-javascript-tutorials-copy-paste-3236</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;"I can follow the tutorial perfectly, but when I try to do it by myself, I have no idea I'm doing."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sound Familiar?&lt;/p&gt;

&lt;p&gt;It's one of the most frustrating situations you can experience as a developer because... what do you do? You were trying to learn how to create projects, and the tutorial was supposed to teach you that... but it didn't work. What are you meant to do now?&lt;/p&gt;

&lt;p&gt;You're almost on the right path – &lt;a href="https://dev.to/canderson93/can-you-actually-learn-javascript-from-an-online-course-5eag"&gt;you need to work on your own projects&lt;/a&gt;. You just need some help in working out &lt;em&gt;how.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let me ask you this: why do you think that you're able to understand the tutorial perfectly? Because &lt;em&gt;you're copying someone else -&lt;/em&gt; and there's a lot of value in it.&lt;/p&gt;

&lt;p&gt;In an ideal world, you'd have an expert sitting next to you all day telling you precisely what to do - but that's a luxury very few people have. Fortunately, you don't need one. Others like you have asked the same questions thousands of times, all you have to do is &lt;em&gt;copy the answer&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The issue is that with a tutorial, you copy &lt;em&gt;everything.&lt;/em&gt; You don't get the opportunity to make the decisions that you need to make to code by yourself. Instead, focus on copying &lt;em&gt;small&lt;/em&gt; sections of code and composing them into a broader application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why you should Copy &amp;amp; Paste
&lt;/h2&gt;

&lt;p&gt;Programmers are absolutely &lt;em&gt;shameless&lt;/em&gt; about copying each others code. We joke about it regularly - and it's our most important skill. Sharing and copying solutions are how we grow as individuals and as a community.&lt;/p&gt;

&lt;p&gt;Liquid error: internal&lt;/p&gt;

&lt;p&gt;Despite this, it's not uncommon to see advice that &lt;em&gt;you,&lt;/em&gt; as a beginner, shouldn't copy code. The thinking is you won't learn anything by copying. This advice, however, ignores the actual difficulty of copying code.&lt;/p&gt;

&lt;p&gt;Make no mistake, copying and pasting code isn't easy. If it were, programmers would be minimum wage workers. It can often take a lot of work and knowledge just to know which code to copy, let alone how to fit it all together.&lt;/p&gt;

&lt;p&gt;What you need to learn at this point is how to solve problems - &lt;a href="https://dev.to/canderson93/can-you-actually-learn-javascript-from-an-online-course-5eag"&gt;you need to work on build projects with JavaScript.&lt;/a&gt; Copying code is a perfect way for you to fill the gaps in your knowledge while you're learning that.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to code with Copy &amp;amp; Paste
&lt;/h2&gt;

&lt;p&gt;Before we begin: &lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;you need a project&lt;/a&gt;. It's hard to write code if your code doesn't have anything to do. You want to start simple and progressively get more ambitious with your projects as time goes on.&lt;/p&gt;

&lt;p&gt;Coding with copy and paste is &lt;em&gt;all about&lt;/em&gt; &lt;a href="https://dev.to/canderson93/practise-javascript-by-breaking-things-down-29gf"&gt;breaking your project down&lt;/a&gt;. This is the hard step - you need to take your project and deconstruct it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can you divide your project into distinct parts? Can you divide those parts further?&lt;/li&gt;
&lt;li&gt;What does each part do (it's behaviour)?&lt;/li&gt;
&lt;li&gt;What actions do you need for each behaviour? Can you divide those actions into smaller actions?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This step isn't easy. It can be hard to know what actions to take when you haven't encountered the problem before. Your list might be incomplete, or wrong. It doesn't matter all that much - if what you have doesn't work, you can just update the list.&lt;/p&gt;

&lt;p&gt;With these actions, there are two golden rules to keep in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The more specific an action, the easier it's going to be to find code for it&lt;/li&gt;
&lt;li&gt;The less complete the portion of code you copy, the better it is for learning. This is why tutorials don't work.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Translate actions into code
&lt;/h3&gt;

&lt;p&gt;Before you start googling how to do each action in your list, take a moment to see if you can do any of them by yourself. This is an excellent way to check what you've learned. As you get better, you'll find yourself needing to copy less and less.&lt;/p&gt;

&lt;p&gt;Write down your answers directly into the code. It doesn't matter if you leave sections incomplete. Put a comment in indicating that you intend to put more code in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
* Function that changes fields based on a dropdown value
*/&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;updateFields&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// TODO: Get the value from the dropdown&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// TODO: Set value of form field&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//TODO: Add event listener to dropdown&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now what you're left with is a big pile of actions that you &lt;em&gt;don't&lt;/em&gt; know how to do – This could be most of your project, or this could be a single step. Either way, it's time to look them up in Google.&lt;/p&gt;

&lt;p&gt;Finding code snippets can be surprisingly challenging. How easy it is to find a snippet depends on the words you've used in your search. While you're looking at answers, it's a good idea to search for other keywords that people use. For instance, I've used &lt;code&gt;dropdown&lt;/code&gt; in the snippet above, but it's represented by &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt; in HTML. Calling it "select" may return more relevant results.&lt;/p&gt;

&lt;p&gt;There's also one final problem: &lt;em&gt;You can't put distinct pieces of code together, and expect it to work.&lt;/em&gt; More often than not, you'll need to change code you've copied to make it fit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
* Function that changes fields based on a dropdown value
*/&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;updateFields&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;:selected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#lastname&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dropdown&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#dropdown&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;dropdown&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;change&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;updateFields&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once your project is working, you can consider this step done. You can stop any point from now, fully satisfied that you succeeded. However, it's a good idea to review your code and see if there's anything you can improve.&lt;/p&gt;

&lt;h3&gt;
  
  
  You've made it work, now make it good
&lt;/h3&gt;

&lt;p&gt;Once you've copied and pasted a bunch of code together, chances are it's a mess. It's no surprise – your code is Frankenstein's monster, sewn together from unrelated parts.&lt;/p&gt;

&lt;p&gt;If your project isn't a throwaway, it's a good idea to go through again and look for any improvements you can make. This can include renaming variables, using newer APIs, etc. At a minimum, you should &lt;a href="https://dev.to/canderson93/introduction-to-readable-javascript-1ffi"&gt;aim to make the code readable&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This is a chance to make the code your own. You need to make it presentable in case you decide to revisit it, or if it becomes a part of your portfolio.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do next
&lt;/h2&gt;

&lt;p&gt;Growing as a programmer is an iterative process - you can't expect to be an expert after a single project. &lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;You should get into the habit of doing dozens of small projects&lt;/a&gt;, both to learn and to form a portfolio.&lt;/p&gt;

&lt;p&gt;The trick here is to keep your projects small so that you can finish what you start, and to consistently set aside time to work on them. Finishing a project is much harder than starting one, and it's a valuable skill that employers will be looking for.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://pages.convertkit.com/9f030a68c9/cd303b3d7b"&gt;Are you stuck on JavaScript Tutorials? Sign up to my newsletter for more helpful articles to get you moving again&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Practice JavaScript by Breaking Things Down</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Thu, 31 Oct 2019 16:58:22 +0000</pubDate>
      <link>https://dev.to/canderson93/practise-javascript-by-breaking-things-down-29gf</link>
      <guid>https://dev.to/canderson93/practise-javascript-by-breaking-things-down-29gf</guid>
      <description>&lt;p&gt;The most important skill you can have as a developer is knowing how to break tasks down - and it's a skill you can practice without a computer.&lt;/p&gt;

&lt;p&gt;As a beginner developer, one of the most frustrating situations you'll encounter is attempting to complete a simple task, but you have no idea where to begin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/canderson93/can-you-actually-learn-javascript-from-an-online-course-5eag"&gt;I've said it before,&lt;/a&gt; but learning JavaScript isn't enough. Hundreds of pieces of JavaScript can be rattling around in your head, but unless you can break down tasks into code, you'll struggle to get a single line out.&lt;/p&gt;

&lt;p&gt;The thing is programmers are &lt;em&gt;constantly&lt;/em&gt; breaking things down and exploring systems around them. A question that regularly floats in our mind is 'how does that work?', or 'how &lt;em&gt;would&lt;/em&gt; that work?'.&lt;/p&gt;

&lt;p&gt;This kind exploration is in this clip from the first season of Silicon Valley (warning: incoming dick references).&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/P-hUV9yhqgY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Yes, it's hyperbole, but I've had discussions with programmer friends where we break down ridiculous ideas like this. It's a lot of fun – and it's a valuable programming exercise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exercise: Breaking down Processes
&lt;/h2&gt;

&lt;p&gt;When you're starting programming, the best thing for you to look for and break down are processes_._ A process is anything that boils down into a series of actions or decisions.&lt;/p&gt;

&lt;p&gt;Our life is &lt;em&gt;full&lt;/em&gt; of processes - how you drive, how the bartender serves you, how you tie your shoes. When you're exploring a process, the first step is to define the actions or decisions in the process.&lt;/p&gt;

&lt;p&gt;Here's a high-level pass at a process that a bartender might follow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Decision: Choose the hottest person at the bar
2. Action: Take their order
3. Action: Make their drink
4. Action: Take their money
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although this explanation is enough for a human to follow, we want to explore this more thoroughly and add more detail by asking two more questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What criteria impact the decisions?&lt;/li&gt;
&lt;li&gt;Are any of the steps also processes?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this example, &lt;em&gt;all&lt;/em&gt; the steps are processes. How do you tell who the hottest person at the bar is? If you add some more detail, it could turn out to be something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Choose the hottest person at the bar
    1. Take a thermometer
    2. Go around every person at the bar, and take their temperature
    3. Choose the person with the highest thermometer reading
2. Take their order
    1. If you're not next to the person, walk over to them
    2. If it's loud, yell the next step
    3. Ask for their order
    4. Wait for response
3. Make their drink
    1. Get a glass
    2. Go over to the beer tap
    3. Pull the tap's handle
    4. Wait until the glass is full
    5. Stop pulling the tap's handle
    6. Place the full glass on the bar
4. Take their money
    1. Put hand out, expectantly
    2. If they didn't order beer, wait until yelling stops then apologise
    3. Else, when money has been placed in your hand, put it in the till
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compared to our last attempt, this is a far more detailed (and revealing) version of a bartender's process. There are &lt;em&gt;still&lt;/em&gt; details missing, but exploring this any further wouldn't be very fun.&lt;/p&gt;

&lt;p&gt;When you're doing this in the world, you can be as detailed, or as thorough as you like. The point of the exercise is breaking down tasks into its component pieces, not creating something you can actually code. Have fun with it.&lt;/p&gt;

&lt;p&gt;If you haven't seen it already, you can also &lt;a href="https://dev.to/canderson93/how-to-write-javascript-when-you-don-t-know-where-to-begin-5f3f"&gt;check out my other article on breaking down programming problems via pseudo-code&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://pages.convertkit.com/9f030a68c9/cd303b3d7b"&gt;Are you stuck on JavaScript Tutorials? Sign up to my newsletter for more helpful articles to get you moving again&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>4 Mistakes That Are Getting You Stuck Learning JavaScript</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Tue, 24 Sep 2019 15:22:52 +0000</pubDate>
      <link>https://dev.to/canderson93/4-javascript-mistakes-that-are-getting-you-stuck-4ic5</link>
      <guid>https://dev.to/canderson93/4-javascript-mistakes-that-are-getting-you-stuck-4ic5</guid>
      <description>&lt;p&gt;When learning to code, you expect to struggle. There's a lot to learn, and it won't all come easily. All you need to do is put your head down, work hard, and chip away at the difficult places bit by bit.&lt;/p&gt;

&lt;p&gt;But what if you've been "chipping away" for weeks with no results? Every time you try to grind through the next chapter or &lt;a href="https://dev.to/canderson93/how-to-write-javascript-when-you-don-t-know-where-to-begin-5f3f"&gt;work out how to write that first line of code&lt;/a&gt;, you get nowhere! &lt;em&gt;You don't get it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You're stuck - and you have no idea what to do.&lt;/p&gt;

&lt;p&gt;Did you miss something important? Do you need to start over, and pay more attention to the basics? What are you doing wrong?&lt;/p&gt;

&lt;p&gt;The good news is that you're not the first person to ever get stuck. I'm going to cover four common mistakes and provide advice on how to get past your sticking point.&lt;/p&gt;

&lt;h2&gt;
  
  
  #1: You're not writing code
&lt;/h2&gt;

&lt;p&gt;Not writing code is the &lt;em&gt;number one&lt;/em&gt; mistake beginners make - and it's by far the most damaging in this list. JavaScript is a tool, so the best way to learn it is to use it - You can't learn to swing a hammer by looking at nails.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/canderson93/can-you-actually-learn-javascript-from-an-online-course-5eag"&gt;I've covered it before in this article&lt;/a&gt; - solving problems with code is different from knowing the language. You're going to have to learn this skill eventually, and the sooner you start, the better.&lt;/p&gt;

&lt;p&gt;Courses will often include some programming exercises, but these aren't enough. You should aim to make your own programming decisions, instead of finding a predetermined solution. With that said, exercises are better than nothing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;You can check out this article if you want help thinking up project ideas.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #2: You're trying to complete topics before moving on
&lt;/h2&gt;

&lt;p&gt;Learning paths in JavaScript are presented linearly. You have to learn all about variables before you learn all about arrays. You need to learn vanilla JavaScript before you learn React/Angular/Vue.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This linearity isn't what learning JavaScript is really like&lt;/em&gt;. We only teach it that way because we have to introduce you to concepts one at a time. It needs to be done in some order.&lt;/p&gt;

&lt;p&gt;Learning JavaScript is not linear. Concepts flow into each other, and later material provides insight into earlier thoughts. Trying to "finish" arrays &lt;a href="https://dev.to/canderson93/when-to-start-learning-a-front-end-framework-9hk"&gt;or vanilla JavaScript before moving on is a waste of time&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Instead, you should gain a shallow knowledge of a breadth of topics, and look it up again when you need more depth:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You should know what each concept is&lt;/li&gt;
&lt;li&gt;You should vaguely understand when/how to use it (so you know when to look it up again)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it. When you're writing code (see #1), that's your chance to revisit these concepts and understand it more.&lt;/p&gt;

&lt;p&gt;If you're stuck with a particular concept, move on and come back to it when you need it. There's a good chance that more advanced ideas will provide the insight you need.&lt;/p&gt;

&lt;h2&gt;
  
  
  #3: You're starting over again
&lt;/h2&gt;

&lt;p&gt;This is the mistake with the highest casualty count for would-be JavaScript developers. In the biz call, we call this "Tutorial Hell".&lt;/p&gt;

&lt;p&gt;When you're completely stuck on a concept, it's tempting to find a new resource and start over. Maybe this one will teach you in a way you understand?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Don't do this.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;JavaScript's core principles are concrete, so beginner resources are relatively interchangeable. A variable is a variable, and that doesn't change. It's unlikely that you're going to get much value by scrapping what you've done, and trying again.&lt;/p&gt;

&lt;p&gt;What you should do instead is practise writing code with what you already know (#1). Rather than spending more time with a concept, move on and go back when you need (as in #2).&lt;/p&gt;

&lt;h2&gt;
  
  
  #4: You're focussing on JavaScript too much
&lt;/h2&gt;

&lt;p&gt;This may seem silly, but your end goal isn't to learn JavaScript. You're learning to program; JavaScript is a means to an end - and you don't even need that much.&lt;/p&gt;

&lt;p&gt;A large part of JavaScript consists of what we call syntactic sugar. These are features that make JavaScript more pleasant to use but don't add any new functionality.&lt;/p&gt;

&lt;p&gt;Once you account for this syntactic sugar, you only need about 20% of JavaScript.&lt;/p&gt;

&lt;p&gt;If you spend too much time learning JavaScript, you'll eventually be re-learning things you already know. Your time is much better spent studying general programming concepts.&lt;/p&gt;

&lt;p&gt;Here are some concepts to get you started:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.cs.utah.edu/~germain/PPS/Topics/truth_tables_and_logic.html"&gt;Boolean algebra (truth tables)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://web.stanford.edu/class/cs103x/"&gt;Graph/Set Theory&lt;/a&gt;. See &lt;a href="https://medium.com/basecs/a-gentle-introduction-to-graph-theory-77969829ead8"&gt;this article too&lt;/a&gt; (Warning: Mathematics)&lt;/li&gt;
&lt;li&gt;Dijkstra's Algorithm&lt;/li&gt;
&lt;li&gt;A* Algorithm&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/sorting-algorithms/"&gt;Sorting Algorithms&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.freecodecamp.org/news/the-top-data-structures-you-should-know-for-your-next-coding-interview-36af0831f5e3/"&gt;Data Structures&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some JavaScript courses cover these topics. If that's the case, you can try skipping forward.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;In this article, I've told you to skip over concepts and ignore large swaths of the language. This doesn't mean you shouldn't expect to learn these concepts eventually.&lt;/p&gt;

&lt;p&gt;The reason for skipping concepts is that we, as individuals, don't use most of JavaScript most of the time.&lt;/p&gt;

&lt;p&gt;Rather than focus on learning a specific concept, you should be writing code. Try to create situations where you need that concept - then revisit it.&lt;/p&gt;

&lt;p&gt;This creates a basic virtuous cycle:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Write code until you find something you don't know&lt;/li&gt;
&lt;li&gt;Learn the thing you don't know&lt;/li&gt;
&lt;li&gt;Repeat&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The crucial part is that you're out there writing code. I recommend checking out my post on &lt;a href="https://dev.to/canderson93/how-to-write-javascript-when-you-don-t-know-where-to-begin-5f3f"&gt;how to write JavaScript&lt;/a&gt; and &lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;finding project ideas&lt;/a&gt; to get you started.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://pages.convertkit.com/9f030a68c9/cd303b3d7b"&gt;Are you stuck on JavaScript Tutorials? Sign up to my newsletter for more helpful articles to get you moving again&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to Write JavaScript When You Don’t Know Where to Begin</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Mon, 12 Aug 2019 15:06:55 +0000</pubDate>
      <link>https://dev.to/canderson93/how-to-write-javascript-when-you-don-t-know-where-to-begin-5f3f</link>
      <guid>https://dev.to/canderson93/how-to-write-javascript-when-you-don-t-know-where-to-begin-5f3f</guid>
      <description>&lt;p&gt;Have you ever tried a coding problem, but ended up staring at a blank editor? Maybe you tried to write a simple function, but didn't even know where to begin?&lt;/p&gt;

&lt;p&gt;It's &lt;em&gt;frustrating&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;After all, you've spent &lt;em&gt;months&lt;/em&gt; working to understand JavaScript's basics. You've learned all there is to know about variables, arrays and functions... but when it comes to coding on your own, you struggle to write a single line.&lt;/p&gt;

&lt;p&gt;It's not that you don't know JavaScript -- You're fully capable of &lt;em&gt;reading&lt;/em&gt; code. It's just when it comes time to putting pen to paper, something is missing.&lt;/p&gt;

&lt;p&gt;How do you get past the blank editor?&lt;/p&gt;

&lt;p&gt;Firstly, it's important that you don't get discouraged. &lt;a href="https://dev.to/canderson93/can-you-actually-learn-javascript-from-an-online-course-5eag"&gt;Starting another course is not the answer.&lt;/a&gt; What you &lt;em&gt;do&lt;/em&gt; need is a method for breaking down your ideas so that you know what code to write.&lt;/p&gt;

&lt;p&gt;I've broken down the system that I use to solve coding problems and provided a step-by-step guide on how to go from idea to code. I'll take you through an example using the Fibonacci sequence to show how it works in action.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to break down problems
&lt;/h2&gt;

&lt;p&gt;(N.B. &lt;em&gt;I refer to "English" a lot here, but you should use whatever language you're most comfortable with)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A flaw in the way beginners try to approach coding is that they try to &lt;em&gt;solve the problem in JavaScript&lt;/em&gt;. This seems like a stupid statement, so I'll say it another way: &lt;em&gt;you need to solve the problem in English first.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/JWF7fOo3XyLgA/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/JWF7fOo3XyLgA/giphy.gif" alt="How to Write JavaScript When You Don’t Know Where to Begin" width="245" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we teach JavaScript, we show you the building blocks of the language. What we don't do is explain how to &lt;em&gt;express ideas&lt;/em&gt; in JavaScript.&lt;/p&gt;

&lt;p&gt;You need to express your ideas in English first, and then &lt;em&gt;translate&lt;/em&gt; into JavaScript. This is done in the following four steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define your &lt;em&gt;problem&lt;/em&gt; in English&lt;/li&gt;
&lt;li&gt;Define a &lt;em&gt;solution&lt;/em&gt; in English&lt;/li&gt;
&lt;li&gt;Write your solution in &lt;strong&gt;pseudo-code&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Translate your solution to JavaScript&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This still might not be very easy the first time you do it - it can take some getting used to. Spoken languages don't force you to clarify your ideas at the level required for coding.&lt;/p&gt;

&lt;p&gt;As you do it more, you'll gain an understanding of what you can and can't do with code, and gain an innate sense for how to express your ideas in a way that translates easily.&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing in Pseudo-code
&lt;/h3&gt;

&lt;p&gt;Pseudo-code is an amalgamation of code and English. There's no correct way to write pseudo-code - you make it up as you go along. So long as it looks a little bit like code, you're doing well.&lt;/p&gt;

&lt;p&gt;The reason we write pseudo-code is that it allows us to write in a language-agnostic way. We use it to skip over unnecessary details in a way that we can easily convert &lt;em&gt;into&lt;/em&gt; code.&lt;/p&gt;

&lt;p&gt;The beauty of pseudo-code over simply writing JavaScript is we can choose whatever level of detail we like. We can use "magic" statements to sketch our ideas without having to worry about implementation details. If it's helpful, we can even write pseudo-code in full sentences.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Both of these functions are perfectly valid pseudo-code
printSortedArray(array):
    sort array
    print each item in array

printSortedArray(array):
    // Bubble sort
    while array is not sorted:
        for each item in array:
            if item+1 is less than item
                swap item and item+1

    for each item in array:
        print item

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example: The Fibonacci sequence
&lt;/h2&gt;

&lt;p&gt;I'm going to run through an example of breaking down a problem and writing pseudo-code. We're going to create a function which returns the nth value of the Fibonacci sequence.&lt;/p&gt;

&lt;p&gt;There are two things to note throughout this process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is highly personal. What I come up with may be different from you.&lt;/li&gt;
&lt;li&gt;It takes longer than it looks. This is a blog post - you skip straight to the end result. You don't get to see the time spent thinking about the problem.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Plain English
&lt;/h3&gt;

&lt;p&gt;Our main goal into this step is to &lt;em&gt;clarify everything&lt;/em&gt;. The more concrete and specific we can be, the better. Initially, it's a good idea to simply &lt;em&gt;define&lt;/em&gt; everything, and then start stating facts about your definitions.&lt;/p&gt;

&lt;p&gt;If we define the Fibonacci sequence problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Fibonacci sequence is the sequence &lt;code&gt;1, 1, 2, 3, 5, 8&lt;/code&gt; etc.&lt;/li&gt;
&lt;li&gt;To calculate any value of the Fibonacci sequence, I have to know the two previous values in the series.&lt;/li&gt;
&lt;li&gt;If I want to know a specific value in the sequence, I need to know every prior value in the chain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This may not seem like much, but it does give us enough to define a simple solution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To get the value for &lt;code&gt;n&lt;/code&gt;, I need to generate the entire Fibonacci sequence up to &lt;code&gt;n&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're able to (and the problem allows for it), you can think up multiple solutions, and choose &lt;em&gt;one.&lt;/em&gt; If it doesn't work out, it's good to be able to come back and try a different path.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pseudo-code
&lt;/h3&gt;

&lt;p&gt;Alright. We now have a specific way to get the &lt;code&gt;n&lt;/code&gt;th value of the Fibonacci series: create all the numbers up until n. At this stage, we want to broadly think about how we're going to code this.&lt;/p&gt;

&lt;p&gt;As I mentioned, the beauty of pseudo-code is that it lets me solve the problem at different levels of detail. It can often pay to solve the problem using "magic" the first time around and add detail as we need it.&lt;/p&gt;

&lt;p&gt;This is how I'd devise a "magic" solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fibonacci (n):
    loop between 0 and n
        sum two previous fibonacci numbers
        when n, return value

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

&lt;/div&gt;



&lt;p&gt;It isn't detailed enough to turn directly into code because of the magic "two previous Fibonacci numbers", but the basic approach is solid. We could absolutely use this as a blueprint to start coding from, filling in the blanks as we go.&lt;/p&gt;

&lt;p&gt;Since this is a demonstration, we're going to do one more round of pseudo-code to add some more detail.&lt;/p&gt;

&lt;p&gt;In this round, we want a little less magic: &lt;em&gt;How do we get the two previous Fibonacci numbers?&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fibonacci(n):
    // We can't get n-2 for 0 and 1, so return them directly
    if n is 0 or 1, return 1

    // Set these to the first two numbers of the fibonacci sequence
    prev1 = 1
    prev2 = 1

    // use 2 here because we've already done when n is 0 and 1
    loop from 2 until n:
        current = prev1 + prev2

        // Update the previous numbers, so we're ready for the next loop
        prev2 = prev1
        prev1 = current

   return current

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

&lt;/div&gt;



&lt;p&gt;At a glance, this looks completely different from our previous solution, but it's exactly the same. We've just clarified how we're going to store the previous Fibonacci values inside of variables.&lt;/p&gt;

&lt;p&gt;This is now a complete solution. While there are some minor details that I may need to add when coding, it will translate into JavaScript almost 1:1.&lt;/p&gt;

&lt;h3&gt;
  
  
  JavaScript
&lt;/h3&gt;

&lt;p&gt;This step should be self-explanatory. Take the pseudo-code code you have, and turn it into the final JavaScript.&lt;/p&gt;

&lt;p&gt;You'll likely need to make some final clarifying decisions (like choosing to use &lt;code&gt;&amp;lt;=&lt;/code&gt; inside of the for loop), but this should look very similar to your pseudo-code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;fibonacci&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// We can't get n-2 for 0 and 1, so return them directly&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;prev1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;prev2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// use 2 here because we've already done when n is 0 and 1&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;prev1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;prev2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Update the previous numbers, so we're ready for the next loop&lt;/span&gt;
        &lt;span class="nx"&gt;prev2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;prev1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;prev1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This isn't the most &lt;em&gt;concise&lt;/em&gt; solution to the Fibonacci sequence, but it is a perfectly valid one. It will &lt;em&gt;definitely&lt;/em&gt; pass a coding interview.&lt;/p&gt;

&lt;p&gt;As I said before, this may not come naturally to you at the beginning. The next step for you to take is to practice. You can go over to sites like &lt;a href="https://www.hackerrank.com/"&gt;HackerRank&lt;/a&gt; to try some of their coding problems, or you can start working on your own &lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;practice projects.&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://pages.convertkit.com/9f030a68c9/cd303b3d7b"&gt;Are you stuck on JavaScript Tutorials? Sign up to my newsletter for articles to get you over the hump and working on the things you want&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>7 Pieces of Bad Advice for JavaScript Beginners</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Mon, 29 Jul 2019 13:17:13 +0000</pubDate>
      <link>https://dev.to/canderson93/7-pieces-of-bad-advice-for-javascript-beginners-477c</link>
      <guid>https://dev.to/canderson93/7-pieces-of-bad-advice-for-javascript-beginners-477c</guid>
      <description>&lt;p&gt;Let's face it - not all advice is helpful, even if it is well-meaning.&lt;/p&gt;

&lt;p&gt;As a beginner, you're especially vulnerable. It's hard for you to tell the difference between the advice which will save you months, or cost you years.&lt;/p&gt;

&lt;p&gt;You could avoid taking &lt;em&gt;any&lt;/em&gt; advice, but the reality of a self-taught developer is you &lt;em&gt;rely&lt;/em&gt; on online advice when you get stuck. How do you tell which advice to follow? How do you &lt;em&gt;progress?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I've seen all sorts of bad advice - the worst of which make repeat appearances. I've compiled a list of some common bad advice, why you shouldn't follow it, and what you should do instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;#1: You should switch to this course/book/resource&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I see this crop up when someone has &lt;em&gt;already&lt;/em&gt; completed a course but struggles to write code by themselves. They still need the aid of a tutorial or guide handing them the answers.&lt;/p&gt;

&lt;p&gt;This piece of advice hurts because it suggests that there is a "perfect" course out there. One that will solve all your problems, all you have to do is find it.&lt;/p&gt;

&lt;p&gt;This is a core contributor to "tutorial hell". Beginners get caught in a cycle of following new tutorials and never addressing the underlying problem. They never learn how to move &lt;em&gt;past&lt;/em&gt; the tutorials. Instead, they start over again, hoping &lt;em&gt;this time, it'll be different.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/F8deaO3psSKiY/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/F8deaO3psSKiY/giphy.gif" alt="7 Pieces of Bad Advice for JavaScript Beginners" width="245" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Beginner resources don't differ by &lt;em&gt;enough&lt;/em&gt; to make it worth starting over.&lt;/p&gt;

&lt;p&gt;You didn't screw up early on. You don't need to start over with a clean slate. You need to spend some more time with the material you've &lt;em&gt;already learned.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/canderson93/can-you-actually-learn-javascript-from-an-online-course-5eag"&gt;I've elaborated on this more in this article.&lt;/a&gt; There are two parts to software development: syntax, and &lt;em&gt;learning how to build software&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Instead of throwing in the towel and re-rolling, start building &lt;em&gt;tiny&lt;/em&gt; projects. What do you already know? Try to think up &lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;some small project ideas&lt;/a&gt; that you can create with the knowledge you already have.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;#2: You should use this framework/library instead&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This isn't "every time you see this, walk the other way" advice. I'm specifically talking about cases where an answer without any real thought.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Hey, How do I change the colour of a div using a button?&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;em&gt;It's way easier if you use React&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There's nothing wrong with suggesting frameworks and libraries. The issue comes when the framework is suggested blindly.&lt;/p&gt;

&lt;p&gt;React doesn't help you change the colour of a div at all_._ The effort it would take to include React would far outstrip the time it takes to solve it some other way. The commenter just likes React.&lt;/p&gt;

&lt;p&gt;That doesn't mean all suggested tech is bad. The important thing here is that you do your research, and make an informed decision.&lt;/p&gt;

&lt;p&gt;Each time you include a new tool, you have to learn how to use it. You may have to rewrite large portions of code. It's up to you to decide whether that cost is worth solving the problem you have.&lt;/p&gt;

&lt;p&gt;Do your research. If it doesn't make sense, move on and find something else. &lt;em&gt;Don't take anyone else's word for it.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;#3: You have to be passionate to learn JavaScript&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I hate seeing this advice.&lt;/p&gt;

&lt;p&gt;This one can rear its ugly head in &lt;em&gt;any thread&lt;/em&gt; about JavaScript. Someone comes along with a story about how they learned JavaScript in 6 months... by spending 12 hours a day living, breathing and consuming nothing but code.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;And if you want to succeed, you need to do it too&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It's too extreme. It glorifies an approach that involves destroying your lifestyle. It suggests that if you have a full-time job, a partner, a young child, or &lt;em&gt;any other hobby&lt;/em&gt;, you can't learn JS.&lt;/p&gt;

&lt;p&gt;You don't need to spend 12 hours a day on JavaScript. You don't need to find 3-6 hours every night to code. You don't even need to be having fun.&lt;/p&gt;

&lt;p&gt;You need to focus on &lt;em&gt;consistently&lt;/em&gt; spending time learning JavaScript.&lt;/p&gt;

&lt;p&gt;You're learning to code. This is a skill you'll develop over the rest of your life, so there's no rush. You're going to be more successful if you can find time in a way that you can sustain forever.&lt;/p&gt;

&lt;p&gt;There's nothing wrong with learning to code in 1-hour chunks, so long as you can &lt;em&gt;keep doing it.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;#4: You need X days/months/years to learn JavaScript&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I can understand the desire to know how long things take. Unfortunately, it doesn't work like that.&lt;/p&gt;

&lt;p&gt;There is no set point where you have "learned JavaScript". Any effort to say how long it takes is inherently flawed.&lt;/p&gt;

&lt;p&gt;The damage here is the implication that there is a point where you'll feel "done". You can work your butt off trying to reach that point, and get more and more disillusioned when it never comes.&lt;/p&gt;

&lt;p&gt;Ignore anyone when they say how long it took them. It's more likely to be the &lt;a href="https://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect"&gt;Dunning-Kruger Effect&lt;/a&gt; than actual anecdotal evidence.&lt;/p&gt;

&lt;p&gt;Instead, focus on tangible goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Starting your first solo project&lt;/li&gt;
&lt;li&gt;Creating a fun SVG Animation&lt;/li&gt;
&lt;li&gt;Getting your first job&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;#5: You need to know about X before you start Y&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This one often comes when someone wants to try something new, like React. About half the time, it includes a &lt;em&gt;very long list&lt;/em&gt; for X.&lt;/p&gt;

&lt;p&gt;You &lt;em&gt;couldn't possibly&lt;/em&gt; start using React until you've learned everything about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Classes&lt;/li&gt;
&lt;li&gt;Functional JavaScript&lt;/li&gt;
&lt;li&gt;Kubernetes&lt;/li&gt;
&lt;li&gt;Quantum Computing&lt;/li&gt;
&lt;li&gt;Crochet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;/sarcasm&lt;/p&gt;

&lt;p&gt;These lists tend to cover &lt;em&gt;everything&lt;/em&gt; the new framework etc. uses (and then some). They're a result of the "waterfall" approach that we seem to love when guiding beginners. "You have to learn &lt;em&gt;all the basics&lt;/em&gt; before trying &lt;em&gt;anything&lt;/em&gt; advanced_."_&lt;/p&gt;

&lt;p&gt;I've talked about this in other articles like &lt;a href="https://dev.to/canderson93/when-to-start-learning-a-front-end-framework-9hk"&gt;When to start learning a Front-end Framework.&lt;/a&gt; You often need far less knowledge to move into advanced concepts than you'd think.&lt;/p&gt;

&lt;p&gt;These lists are useful though: They are a syllabus for the framework. It's a list of what you &lt;em&gt;will&lt;/em&gt; learn if you choose to learn React.&lt;/p&gt;

&lt;p&gt;The important thing here: Don't let it stop you. Don't worry about having to look stuff up.&lt;/p&gt;

&lt;p&gt;Motivation is hard. It's easier if you're spending time working on things that you want to work on.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;#6: If you can't even do X, you don't deserve to be a programmer&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Okay. You've got me. This isn't exactly advice. It's the programming version of schoolyard bullying. While infrequent, this can show up anywhere.&lt;/p&gt;

&lt;p&gt;The reason this is here is that it preys on insecurity present in &lt;em&gt;a lot&lt;/em&gt; of struggling beginners. "I don't get it - maybe I'm not &lt;em&gt;meant&lt;/em&gt; to be a programmer?".&lt;/p&gt;

&lt;p&gt;Any time you see this, you're not seeing an actual critique of "what it takes to be a programmer". You're seeing someone posturing - someone who is insecure about their own programming.&lt;/p&gt;

&lt;p&gt;Notice how it is &lt;em&gt;never&lt;/em&gt; accompanied by an actual answer?&lt;/p&gt;

&lt;p&gt;Are you willing to put in the time to learn to code? You deserve to be a programmer.&lt;/p&gt;

&lt;p&gt;Learn things at your own pace. For every dickhead comment like this, there are plenty of others that will actually help.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;#7: You should learn this other language instead&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It may seem strange that this advice is around. This often finds its way into discussions about how to break out of tutorial hell.&lt;/p&gt;

&lt;p&gt;Learning another language is weird advice in that can &lt;em&gt;kind of work.&lt;/em&gt; It provides a new perspective on programming, which may be what you need to break out of tutorial hell.&lt;/p&gt;

&lt;p&gt;The issue is that tutorial hell exists no matter what language you're in. Learning C or Ruby isn't going to fix your problem. It provides a different set of tutorials to keep you in hell.&lt;/p&gt;

&lt;p&gt;Your time is better spent &lt;em&gt;addressing the problems you're having with writing JavaScript.&lt;/em&gt; &lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;Write some small projects&lt;/a&gt;, do some coding exercises, write all the sorting algorithms. &lt;em&gt;Practice&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Afterword&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I'm sure you've noticed a trend in my suggestions: Be consistent in your learning, and &lt;em&gt;write code, damn it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you're struggling with what to build, I recommend &lt;a href="https://dev.to/canderson93/how-to-find-ideas-for-good-practice-projects-5hcm"&gt;reading this article about finding project ideas&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you want to read more about tutorial hell, you can check out this article: &lt;a href="https://dev.to/canderson93/can-you-actually-learn-javascript-from-an-online-course-5eag"&gt;"Can you Actually Learn JavaScript from an Online Course"?&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://pages.convertkit.com/9f030a68c9/cd303b3d7b"&gt;Having a hard time learning JavaScript? Sign up to my newsletter for articles like this straight to your inbox&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>3 Techniques for Maintaining Your Sanity Using "This" in JavaScript</title>
      <dc:creator>Carl Anderson</dc:creator>
      <pubDate>Wed, 17 Jul 2019 14:28:32 +0000</pubDate>
      <link>https://dev.to/canderson93/3-techniques-for-maintaining-your-sanity-using-this-in-javascript-3idf</link>
      <guid>https://dev.to/canderson93/3-techniques-for-maintaining-your-sanity-using-this-in-javascript-3idf</guid>
      <description>&lt;p&gt;Of JavaScript's many confusing aspects, the keyword &lt;code&gt;this&lt;/code&gt; can be one of the most complicated -- Here's a joke about the troublesome keyword:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-578925947245633536-298" src="https://platform.twitter.com/embed/Tweet.html?id=578925947245633536"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-578925947245633536-298');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=578925947245633536&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt; is &lt;em&gt;frustrating.&lt;/em&gt; Every time you think you have it, another weird case shows up - it should be &lt;em&gt;simple,&lt;/em&gt; so why does it never seem to work how you want it to?&lt;/p&gt;

&lt;h1&gt;
  
  
  Why "this" is confusing
&lt;/h1&gt;

&lt;p&gt;In other programming languages, &lt;code&gt;this&lt;/code&gt; &lt;em&gt;always&lt;/em&gt; refers to the current instance of an object. It's a very consistent keyword which will only ever hold two values: the current object, or nothing.&lt;/p&gt;

&lt;p&gt;In JavaScript, &lt;code&gt;this&lt;/code&gt; refers to what is known as the &lt;em&gt;execution context&lt;/em&gt;. In practical contexts, this is &lt;em&gt;deceptively similar&lt;/em&gt; to other languages version of &lt;code&gt;this&lt;/code&gt;, but contains a fundament difference: the execution context is different based on &lt;em&gt;how&lt;/em&gt; a function is called_._&lt;/p&gt;

&lt;p&gt;This means that JavaScript's version of &lt;code&gt;this&lt;/code&gt; may have different values depending on how you called the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;trigger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Because of how the function is being called, `this` can have&lt;/span&gt;
        &lt;span class="c1"&gt;// several different values&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;brokenTrigger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// `this` will refer to the current object, so it will act as we expect&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trigger&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// setTimeout resets `this` to the global context object - in web&lt;/span&gt;
        &lt;span class="c1"&gt;// browsers, it is the Window object&lt;/span&gt;
        &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;trigger&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// When we refer to the function directly (without the object)&lt;/span&gt;
        &lt;span class="c1"&gt;// `this` refers to the global context object (window)&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;unboundFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;trigger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nf"&gt;unboundFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Event listeners replace "this" with the target element &lt;/span&gt;
        &lt;span class="c1"&gt;// `this` will refer to the clicked ".triggerButton"&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.triggerButton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;trigger&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  How to use &lt;code&gt;this&lt;/code&gt; safely
&lt;/h1&gt;

&lt;p&gt;When you see all the ways that &lt;code&gt;this&lt;/code&gt; can go wrong, it seems like the easiest option is to throw your hands in the air, become a hermit and start a small potato farm.&lt;/p&gt;

&lt;p&gt;In practice, &lt;code&gt;this&lt;/code&gt; tends to be far less problematic than these examples make it appear. Most of the weird behaviours of &lt;code&gt;this&lt;/code&gt; are easy to avoid by restricting your use of &lt;code&gt;this&lt;/code&gt; to object functions, where it is the most consistent&lt;/p&gt;

&lt;p&gt;As I said in the intro, using &lt;code&gt;this&lt;/code&gt; with an object is &lt;em&gt;almost always&lt;/em&gt; going to refer the object instance, but you do have to watch for two major exceptions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;setTimeout&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;addEventListener&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In these cases, we have several techniques at our disposal to control the value of &lt;code&gt;this&lt;/code&gt;, and to make sure that it works how we want.&lt;/p&gt;

&lt;h2&gt;
  
  
  Technique 1: Use Fat Arrow Functions
&lt;/h2&gt;

&lt;p&gt;Fat Arrow Functions, aside from being a quick way of declaring functions, differ slightly from other function declarations in that they won't allow anything to overwrite &lt;code&gt;this&lt;/code&gt;. Instead, it keeps the value from where the function is declared (its lexical scope).&lt;/p&gt;

&lt;p&gt;What this means is that we can use them as wrappers, or directly as event listener function calls to preserve our &lt;code&gt;this&lt;/code&gt; reference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// `this` still refers to Foo&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.class&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
            &lt;span class="c1"&gt;// or&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Technique 2:  Assign &lt;code&gt;this&lt;/code&gt; to a variable
&lt;/h2&gt;

&lt;p&gt;Before ES6, a popular pattern was to copy the value of &lt;code&gt;this&lt;/code&gt; when we knew it referred to our object and used the new variable instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// These are both common names for our new `this`&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;that&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.class&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Technique 3: Explicitly set &lt;code&gt;this&lt;/code&gt; with &lt;code&gt;Function.bind&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Functions come with several tools to set the value of &lt;code&gt;this&lt;/code&gt; explicitly so you can guarantee the value of &lt;code&gt;this&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Function.bind&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Function.apply&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Function.call&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In practice, &lt;code&gt;Function.bind&lt;/code&gt; is the most useful of the three, since it doesn't immediately call the function, instead returning a new version with a pre-set &lt;code&gt;this&lt;/code&gt;, and any parameters you pass - you can use this new function directly in &lt;code&gt;setTimeout&lt;/code&gt; or &lt;code&gt;addEventListener&lt;/code&gt; function and keep your value of &lt;code&gt;this&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// The first paramter of `bind` is the new `this` value&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.class&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;handleEvent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Bonus Technique: Use Strict Mode
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode" rel="noopener noreferrer"&gt;JavaScript's Strict Mode&lt;/a&gt; slightly changes the behaviour of &lt;code&gt;this&lt;/code&gt;. Instead of implicitly setting &lt;code&gt;this&lt;/code&gt; to the global context outsides of objects, it causes it to be &lt;code&gt;undefined&lt;/code&gt; instead.&lt;/p&gt;

&lt;p&gt;In practical terms, this is a fairly minor change, but it prevents several incorrect usages of &lt;code&gt;this&lt;/code&gt;, and cause a would-be-hidden bug to throw an error instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Normally this will create an `x` property on the global object and&lt;/span&gt;
        &lt;span class="c1"&gt;// continue running, but in strict mode this will throw an error&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Breaking the reference to `obj` causes `this` to be undefined instead&lt;/span&gt;
&lt;span class="c1"&gt;// of referring to the global object&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;func&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;update&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Don't overcomplicate it
&lt;/h2&gt;

&lt;p&gt;If you regularly read my blog, you'll know this is basically my slogan.&lt;/p&gt;

&lt;p&gt;There's no denying that &lt;code&gt;this&lt;/code&gt; is &lt;em&gt;strange,&lt;/em&gt; but that doesn't mean that you need to worry about all the edge cases that it presents - More often than not, they don't come up.&lt;/p&gt;

&lt;p&gt;I've been a Web Developer for coming on eight years now, and I learned some new edge cases about &lt;code&gt;this&lt;/code&gt; when preparing this post that I have never encountered before.&lt;/p&gt;

&lt;p&gt;If you're interested in learning more about JavaScript, you can check out &lt;a href="https://dev.to/canderson93/javascript-closures-and-how-they-work-51bk"&gt;this guide to closures&lt;/a&gt;, or read this article about &lt;a href="https://dev.to/canderson93/when-to-start-learning-a-front-end-framework-9hk"&gt;what you need to know to start learning a front-end framework&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://pages.convertkit.com/9f030a68c9/cd303b3d7b" rel="noopener noreferrer"&gt;Having a hard time learning JavaScript? Sign up to my newsletter for articles like this straight to your inbox&lt;/a&gt;.&lt;/p&gt;

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