What Makes Good Code?

Modern JavaScript Introducing JavaScript
3 minutes
Share the link to this page
Copied
  Completed

Transcript

Now as you get started writing JavaScript, you are going to be coding. So I want to take just a few minutes to talk about what makes good code. These items I think are important to keep in mind as you learn JavaScript. The first thing that I think makes good code is that code needs to do what it's supposed to do. Obviously, if it's not working, it's not going to be very effective. So that that needs to be accomplished first.

But in addition to that, it can be helpful if it's small in size, especially where JavaScript is concerned. Since JavaScript is generally used in the browser, it needs to be downloaded before it can be run by the JavaScript engine. So the smaller and sizes it is the faster downloads that can help make the web page much more responsive for the user. Minimum complexity is an important thing for making good code. You may not be the only one that has to read the code that you write, or you may need to come back to that code after many months or even years of not seeing it. If it's very complex, it can be difficult for yourself or someone else to figure out.

And so if you can minimize the complexity that can help in the future, or it could help somebody else that comes in and needs to work with the code. The code also needs needs to be manageable. Now what do I mean by that? It can save you a lot of time if you structure your code so that it is manageable. Let me give you just one example. JavaScript code can be written directly in the HTML page, or it can be written in a separate JavaScript file.

By writing it in a separate JavaScript file, it can help make it more manageable in a number of different ways. One example would be You could be using that same JavaScript file for several HTML pages. If you are not writing it in its own page, you would have to repeat it in each of the HTML pages. Then if you needed to make an update, you'd have to go to each of those HTML pages to make that update where when it's in a separate file, you can make it in one place, and updates for all the pages. That's just one example of manageable code. As we go through the course, and as as we encounter situations where you can help make your more your code more manageable, I will mention those.

Finally, the last item that can help make good code is making it readable. One of the first topics we'll discuss as we get started in this course, is how to help make your code readable not only for yourself, but for others that come to the code making sure that they can quickly see what's what the code is trying to do. That can save a lot of time. So those are some concepts to keep in mind as you begin writing JavaScript code.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.