Over the course of a few days I worked on and finished the Intro to Ruby module. Overall it was a lot more enjoyable than Codecademy. While Codecademy is definitely a great resource to learn programming basics, I find the content can be a little dry and the site holds your hand too much. The Ruby modules on First Draft were great and it pushed you to think about what you learned when doing the graded code blocks.
I have a little over a year of learning JavaScript so I love to see some of the differences between JS and Ruby. Below are a couple of differences I noticed while working on the modules.
Truthiness and Falsiness
While working through the 'If statements' module i noticed that Ruby has less 'falsy' values compared to JavaScript.
In Ruby, only false
and nil
are consdered falsy values.
JavaScript on the other hand has the following falsy values.
false
undefined
null
0
-0
On
NaN
""
Equality
Another area were Ruby differs from JavaScript is the equality operator. In Ruby you can only use
==
!=
In JavaScript you have access to a third equality operator.
!= // not equal to
== // loose equality, equal to but attempts to convert operands that are different types
=== // strict equality, both operands must be same type
Using the ==
operator can create problems in your code
// The following code returns true
'2' == 2
This can lead to errors in your code, so generally it is recommended to always use the strict equality operator.
While Ruby does have a ===
operator, it is not used for comparing equality. The ===
operator in Ruby checks if an object belongs to a class or range. It can be used like this:
(1..10) === 1
# => true
String === 'foo'
# => true
Overall I really like the simplicity of Ruby. It is easy to type and it doesn't have a lot of curly braces and parentheses all over the place like JS.
Top comments (0)