Reinforcing through repetition — How learning JavaScript is helping me re-learn Ruby

Recently I decided to pursue becoming a React on Rails developer. While I became enamored in what React can do and how it works with the Rails framework, I realized then it was a must to understand the language that was powering it. That means learning JavaScript which seems scary especially since I have just a basic understanding of Ruby. How am I supposed to learn two programming languages at once?

First step was to head back over to freeCodeCamp which I started a few months back but then backed off due to how difficult it was. The experience points remained in tact on my account but I knew I had to go back to the beginning in order to gain an understanding of how JS works. The difference between then and now is that instead of powering through each exercise, I’d tinker with the solution. Switching up the test argument so the output produced a different result and refactoring the code to come up with a more efficient solution soon enough became a common practice.

Then it hit me. The very thing that eventually happens to all novice developers. It finally clicked!

Through learning JS it helped me better understand Ruby. Despite subtle and not-so-subtle differences, they have similarities. For example one of the coding challenges from FCC was to create a program that would convert a temperature degree from celsius to fahrenheit. Here was my solution written in JS.

Now here is my solution written in Ruby.

Despite the differences in syntax, they couldn’t be any more similar. “function” in JS is the equivalent to “def” in Ruby. They’re both used to establish the function of that block of code that will eventually be called upon based on the argument(s).

The formula to convert celsius to fahrenheit is similar in both cases since both JS and Ruby follow the PEMDAS rule to calculate equations. The difference being that in JS you have to add “var” in order for the function to be executed, call the method within the function, and be mindful of bracket and semi-colon placement. Ruby simply requires you end each function with “end”.

Ever since this exercise I make it a point to not only find the solutions but also to translate it from JS to Ruby and it’s helped me learn and understand both languages (and by extension programming in general). What was frustrating at first is now starting to become fun!

Like what you read? Give Wil Santana a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.