Week 2: A brief about JavaScript, clean code, and unit testing

Subscribe to my newsletter and never miss my upcoming articles

👋 Hey everyone. Welcome back.

It's week 2 of my #12weeks12blogs challenge. And I must say it's not easy to stay motivated all the time. I realized the importance of knowing your next move. Discipline is hard. So I spent an entire day thinking, planning, and digging my bookmarks of resources, to create an ultimate plan based on my goals.

master plan.png

🐣 Back to basics

It's weird. The same topics when you revisit after a long time, you understand a lot differently. You get a new perspective and lots of ' Oh, so this is how it works' moments.

This week I revisited DOM and it's basic concepts like

  • Accessing dom elements
  • Traversing the dom and making changes to it.
  • Handling different events in JavaScript

And made a simple app that counts characters, words, and estimates reading time while typing. It was super easy and fun. You can see it live here.

counterbox.gif

One good thing I observed was how I was coming up with better solutions every time. It's a big win. And that brings me to the importance of writing clean code.

🤷‍♂️ Why clean code?

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler

Even the bad code works well. Then why should I care about writing clean code? It's simple. Clean code is easy to understand, change, and maintain. If you want to be a good programmer, clean code is important. I went through the code I wrote a year ago and now I know. When I first heard about clean code, I thought it's just indenting the code well. But it's way more than that. Here are a few things I learned about clean code.

  • Use meaningful names for variables, functions, classes, etc. Robin Wieruch has explained it really well in this blog.
  • Make your Functions do one thing
  • Write comments only when needed. Good code mostly documents itself.
  • Don't repeat yourself.

It will take some time and practice for me to write clean code. It's an iterative process of learning and improving. Clean Code by Robert Martin is next on my reading list. But for now, this repo is enough to get started.

ReadMe Card

✅ Unit testing in JavaScript

Testing is simply checking if our code is working right or not. And unit testing is a technique where we divide our code into small isolated units and then write tests to check if the unit works as expected.

I explored Jest, a popular JavaScript testing framework, and wrote my first unit test. The jest docs are pretty good. And this series on the unit testing by fun fun function is too good. Testing is an important aspect of software development and I will definitely dive deep into it in the nearby future.

So far it's been a great start for me, and I am very excited to learn more in the upcoming weeks.

Thread of the week:


I keep writing about the things I learned and applied. So you can connect with me on Twitter, Github or Linkedin. Also, subscribe to my newsletter and stay up-to-date with my latest blog posts.

⚡ Happy Learning!

Rahul's photo

Rutik man you killed it badly. Amazing and best blog post.

Rutik Wankhade's photo

Thank you so much Rahul. 😊👍

Jennifer Openshaw's photo

Enjoyed reading your blog post :) That counter is really cool!

Rutik Wankhade's photo

Thanks, Jennifer Openshaw. I see you are documenting your progress from a Bootcamp too. Cheers!

Dany Tulumidis's photo

Nice Post! Keep going and the motivation will come. Most poeple think we need motivation to start something but its the other way around: The motivation will come while we doing stuff.

And here is a JS Repo with some questions: github.com/lydiahallie/javascript-questions.. Some of them are quite hard but its fun!

Rutik Wankhade's photo

Thanks, Dany Tulumidis I totally agree with you. do stuff-get motivated-do stuff. It's a cycle. Also thanks for sharing the repo. It's really helpful.

Tapas Adhikary's photo

Rutik Wankhade, Great going.. Looking forward to the next week.

Rutik Wankhade's photo

Thank you 😊