DEV Community

Cover image for Javascript vs Ruby
aidoskashenov
aidoskashenov

Posted on • Updated on

Javascript vs Ruby

Being a complete novice in `Javascript` and having some very limited exposure to `Ruby` I can already point out some distinctions and similarities of syntax and overall logic in two languages.

I'm guessing that my list will cover only 5% of overall differences and similarities between the two, however this is strictly a description of my personal experience and attitude overall.
As in JS in Ruby the Strings, Numbers, Booleans, Arrays and Objects are the same. However Objects are called Hashes in Ruby and are dealt with slightly different. Another, pleasant surprise for me was that a lot of built-in methods are the same and have same, or almost same name. For Example: .length .forEach .push .pop .unshift etc.
However, right now, on my second week of learning Javascript my biggest challenge is dealing with the syntax and overall layout of the code, mostly this - "{" thing. What in Ruby dealt with "end" statement, JS puts in "{" that, for me personally, makes it harder to trace one piece of logic, it's starting and ending point.
Another very interesting thing for me, was that you can add a "String" to a "Number" or a "null" to basically anything. Ruby will immediately protest such a behavior giving out:"TypeError: no implicit conversion from nil to integer". In Ruby you cannot concat any type of data to another type without convert it to the same.

21 + "21" === "2121"
// in Ruby will look like this
21.to_s + "21" == "2121"

There are many more differences between two languages that I am very anticipated to explore

Top comments (3)

Collapse
 
swiknaba profile image
Lud • Edited

In Ruby, try this 😁

'21' * 2

to keep it DRY and funny.

(then try the same in JS and compare!)

Collapse
 
swiknaba profile image
Lud

oh, btw. if you are still learning Ruby, read through github.com/rubocop-hq/rubocop. It will teach you many things AND already explains what is good/bad style for Ruby.

Collapse
 
alexsh profile image
Alex

Ruby win! :)