- See more at: http://blogtimenow.com/blogging/automatically-redirect-blogger-blog-another-blog-website/#sthash.YsVbCxL0.dpuf Journey to Becoming a Web Developer: Differences between JavaScript and Ruby

Sunday, January 19, 2014

Differences between JavaScript and Ruby

Next week at the Flatiron School we will be learning JavaScript. We were asked to blog about some the differences. Here is what I have observed.

Values 
In JavaScript datatypes such as string or number are called values while in Ruby they are just called data types.  Other values in JavaScript are booleans, objects, and, undefined values. Operators in JavaScript are used in the same way as they are in Ruby.  One operator in JavaScript that I learned about is typeof. It can give you the type of value something is. Ruby has something similar which is the method class which can give you the class of an object. 


Variables
JavaScript and Ruby both hold data in variables. In JavaScript syntax var is used before the variable name and in Ruby the variable name alone is used. 
JavaScript




Ruby





 Functions in JavaScript are similar to methods in Ruby.  In JavaScript alert is a variable that contains a function that takes one parameter and shows the result of the expression.  This example  in JavaScript will return the largest number in the argument. 




Math.max is the function that returns 4. In Ruby the method that does this is called max. The same example in Ruby would look like this:




Loops
Loops are used in Ruby and JavaScript in the same way, but the syntax is different. I will show an example of how a while loop looks in JavaScript vs. Ruby.

JavaScript

Ruby








No comments:

Post a Comment