Lilly Winfree
Feb 18 · 3 min read

So you want to do web development? How do you decide which programming language to learn?

There are a lot of options: Ruby, JavaScript, Python, PHP, HTML, CSS…the list goes on. To help you choose, you might consider which city you live in (I’ve been told that Chicago is a “Ruby city” for example), or you could look at job descriptions and see which languages your favorite companies use. I personally started by learning Ruby, and have since started learning JavaScript. It has been interesting to see how these languages are similar and different, and which is better for different web development tasks. I thought I would share what I’ve learned to help others decide where to start!

Differences in Syntax

Many differences between Ruby and Javascript are syntax. One of the most useful differences to know is how we print statements. In Ruby, we use p or puts, but in Javascript we use console.log(). Also, in JavaScript, we end code lines with a semicolon ; . Another important difference is how a method is written. In Ruby, we use def while in JavaScript we use function(){}. For example in Ruby:

def counter
# function code
end

and in JavaScript:

function counter(numbers) {
/// function code
}

Also, it is good to note that comments begin with # in Ruby and in // in JavaScript.

Another difference is that JavaScript uses curly braces {} where Ruby uses end statements. This can be seen in the above example and also in conditional statements. For example, in Ruby:

if number == 1
p number
else
p number + 1
end

Whereas in JavaScript:

if (number === 1) {
console.log(number);
} else {
console.log(number + 1);
}

There are two other things to note from the example above. One is that the conditional statement needs to go in parenthesis. The other is how we do comparisons: in Ruby we use == while in JavaScript we use three equal signs, ===. JavaScript also has a meaning for ==, but it is a less strict comparison. For example: 5 == ‘5’ would be true in JavaScript (but false in Ruby).

What about loops? Well, loops do exist in JavaScript, and they work the same way, but again have different syntax. Let’s look at an each loop. In Ruby:

numbers = [1, 2, 3]
new_numbers = []
numbers.each do |number|
new_numbers << number + 1
end
p new_numbers

And in JavaScript:

var numbers = [1, 2, 3];
var new_numbers = [];
numbers.forEach(function(number) {
new_numbers.push(number + 1);
});
console.log(new_numbers)

In this last example, we see a few differences. First, the loop in JavaScript uses forEach instead of each, and then we need a function. Another difference is when we define a variable in JavaScript, we use the word var (we don’t need a word in Ruby). Next, we see that JavaScript uses .push() instead of << in Ruby.

Overall, these Ruby and JavaScript examples are pretty similar once we learn the new syntax.

When to use…

There are many reasons while you might pick Ruby or JavaScript for different tasks, and I will write more on this in the coming weeks as it deserves it’s own post!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade