JavaScript Tips For Beginners
JavaScript was not my first programming language yet the learning curve seemed very steep. JavaScript just felt foreign, even at points unnatural. I just could not get my head around it. With this being quite early on in my course, I was beginning to feel like maybe I wasn't a natural coder or programming wasn't for me. It has taken me quite a while to build my confidence with JavaScript. I now use it almost daily and with numerous libraries and frameworks from jQuery to Vue.js to Highcharts. I wanted to share some of my tips for learning JavaScript for when it starts to pickle your brain.
Console.log
It might seem super simple but use console.log as much as you need. Don’t be shy! Using console.log is a really good way of testing and debugging your code. You can print values or check variables and test functions or methods.
Comments
Especially at the beginning, add comments. Of course don’t go overboard! Adding comments can be really useful if you are struggling to remember what everything you wrote actually means. I have added comments during the development process, then removed them before committing.
Breakpoints
Breakpoints are really good way for testing and debugging your code. You can stop your code at a particular point to see if a certain statement has been executed. You can use different options to go through each line of code once the break point has been hit or to step into the next one. It then allows you to see if, for example, a variable was populated with the correct data. For JavaScript you can add breakpoints to your code in developer tools, in the sources tab. From there you can add a point to the code you want executed. I didn’t learn this until I started working as a developer and has helped me hugely!
Write it Down
At the beginning I was getting very twisted with JavaScript. Getting my head around what the code was doing and what it looked like were two different things. I would write down the function or for loop and break down what I needed it to do. It helped a lot to visualise what I was doing. I appreciate this may not be for everyone but some times simplifying what you want your code to do can help.
These may seem simple but sometimes it is the simplest things that are the most effective!