Comparison of Ruby and Javascript

Nancy Do
Nancy Do
Sep 3, 2018 · 4 min read

Naming Convention

Ruby: snake_case

JavaScript: camelCase

Falsy Values

Classes

initialize vs constructor

Ruby:

JavaScript:


REPL Interface

irb and node

Ruby: Playing with Ruby code in interactive sessions is a great way to learn the language. If you don’t have Ruby, install it here.

JavaScript: To see if you have Node installed locally, type in your console:

node -v

If not, install it here.


Determine Data Type

.class and .constructor

Append .constructor to objects in JavaScript and.classin Ruby to determine what type of data something is (i.e. Number, Fixnum, String, Object, Hash, Array, etc.).

Ruby: See other possible class types.

JavaScript: See other possible constructor types.


Methods

.method_name vs .methodName()

Ruby: Methods that do not take an argument don’t require parenthesis (i.e. .upcase)

"example".upcase => "EXAMPLE"

JavaScript: Almost all methods require parenthesis at the end to execute.

"example".toUpperCase() // "EXAMPLE"

Debugging

Ruby: binding.pry

JavaScript: debugger


Strict Equality Operator

Ruby: == checks not only the equality of the two values but it also compares the types of the two values too (i.e. 5 === “5” returns false, 5 === 5 returns true).

JavaScript: === works just like Ruby’s == operator would. JavaScript also has its own == operator and should not be confused with Ruby’s.


Arrays

.each vs .forEach

Ruby:

JavaScript:


Variables

Ruby: You can simply set any non-reserve word equal to any value, including null. A variable that begins with an uppercase letter is known as a constant and has different characteristics.

var_name = "hello"
DOGS = ["fido", "snoopy", "nala"]

JavaScript: The process of declaring a variable is and actually setting the value of that variable are two separate processes which are generally grouped into one line.

const blah = "hello"
let hey = "yo"
hey = "no" //reassigning value


Parsing

to_i vs parseInt()

Ruby: Converting a string to a number is quite simple in Ruby as you would just append .to_i to the string.

JavaScript: The parseInt() function also parses a string and returns an integer.


String Interpolation

#{} vs ${}

Ruby:

JavaScript:


Looping

The looping syntax is different for the two languages and it’s obvious which one is more simple.

Ruby:

JavaScript:

Conclusion

Ruby and Javascript both have their advantages and disadvantages. I learned Ruby first and thought it was much less of a rollercoaster than learning JavaScript. Either way, there’s only one way to get better at programming and that’s by practicing AKA coding, coding, coding, and some more coding.

Enjoy the ride (or try to)!

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