JavaScript Vs. Ruby on Rails

Transitioning from Ruby to Javascript was a bit of a rocky road.. so i thought it would be cool to to a blog about them both, compare them & see a few differences and similarities :).

so let compare..

Equals sign.

ruby: ==, =. ruby uses == to compare 
while using the = to assign.
javascript: ===, == , = javascript uses === to compare and also uses the == to compare the difference between these two is === is very accurate and == is leniate when comparing. meaning === checks for types & == does not.javascript example:
a = 10
b = '10'
a === b returns false
a == b returns true
so the === in javascript is equivalent to == in ruby the = in javascript is the same as ruby. (it's used to assign)

&& and || (and & or)

JavaScript uses && and || the same as Ruby.

String Interpolation

this is slightly different Javascript uses ticks (``) in the front and end of a string interpolation and uses ${} to interpolateexample:
`hey, this is a
${Javascript} string interpolation example`
Ruby uses a plain quotation mark ('') in front and end of the string and uses #{} to interpolateexample:
'hey, this is a #{Ruby} string interpolation example'

Although you can still use the a couple of other ways to add strings together like
- .concat,
- the
+ operator, I find the previous example much simpler to use.

self vs. this

Ruby's self is basically the same as JavaScript's this.

Functions Vs. Methods

def (ruby) is equivalent to function() (javascript)ruby example: def ruby
puts "hello"
end
___________________
javascript example:function javascript() {
return "hello"
}

Iteration

.map is the same in ruby as it is in javascript.ruby example:
array.map { |string| string.name }
only difference is the way the iteration is written...javascript example:
array.map(string => string.name)
Map returns a new array with the results.
.each vs forEach
.each in ruby is the same as forEach in javascript. Example... array = [1, 2, 3, 4]ruby example:
array.each {|num| num}
javascript example:
array.forEach(num => num )

Object vs. Hash

Ruby's Hash is the same as JavaScript's Object javascript example:
const cat = {color: “grey”, name: “Spot”, age: “12”};
ruby example:
cat = {color: “grey”, name: “Spot”, age: “12”};
only difference is ruby doesn't need var, const or let to assign a variable a value.

camelCase vs. under_score

we name variables in javascript using camelCase in Ruby we use under_score.ruby example: let javascriptVariable = camelCase javascript example:ruby_variable = under_score 

null vs. nill

Ruby's null is the same as Javascript's nill.

That’s just a few of the many similarities and differences… of JS and ruby hope this was a bit more helpful into conversion if you are converting..

thanks for the read :)