Ruby vs Javascript: A Quick Overview

This is simply an overview for those of you with little or no programming experience to have a basic overview of the major differences between Javascript and Ruby: Which one should you choose if you are just starting out, their fundamental architectural differences and also how you the bidding coder would be able to manipulate it as you see fit. So lets get started.

Historical Differences

Since the first language I learned was Ruby, I will start with that. Ruby was developed by a group of people, leading the design team Osaka born Yukihiro Matsumoto . He, and I quote, “really wanted a genuine object-oriented with easy-to-use scripting language” that Python just didnt have but also taking influences from Perl which he really liked but referred to it as a “Toy Language”. It first appeared around the year of my birth 1995 and now is on version 2.2.0 after 20 years.

Javascript on the other hand was developed by Brendan Eich, in a trivial 10 days also in 1995. Ech was initially hired by Netscape Communications (Now subsidiary of AOL) to put Scheme in the browser to compete with Microsoft for adoption of platforms within the browser, instead he made what is known then as Livescript but was quickly renamed to Javascript . Within a year Javascript gained widespread usage as a scripting language and was adopted by Microsoft’s Internet Explorer 3.0 in 1996.

Linguistic Differences

So Ruby and Javascript are fairly similar as they both use Object Oriented Programming , they are both Dynamic Languages , General Purpose Languages and Scripting-Languages . Well what does that mean Scripting Languages are languages that support programs written for a special ‘Runtime environment’ that can interpret rather than compile. A general purpose language, Object Oriented Programming is where a programming language can create these elements called Objects that represent some form of data as opposed to actions. This makes it much easier for the programmer to manipulate an objects data. Theres a little more detail but for the sake of time I’ll move onto the more useful Syntactic Differences.

Syntactic Differences

So as some people who are familiar with programming in general will know of the concept of : Variables, Hashes , Semicolons, Methods, For Loops , While Loops, Conditionals and Classes. Im going to go over how they are called in both languages so you can see the difference.

Variables:

In ruby variables are relatively easy to set, you just have to type in

variable_name = variable_value

In Javascript its a little bit longer but essentially the samething.

var variable_name = variable_value

Hashes:

In ruby hashes are referred to like so:

hash_name = { hash_key: hash_value , sechash_key: sechash_value}

In Javascript hashes are referred as Objects , the “Key” in Ruby is simply a variable.

var hash_name = { hash_key: hash_value , sechash_key: sechash_value}

You can call upon the hash to find the value of a key in ruby by using

hash_name[:hash_key] —-> hash_value

In Javascript you can call the “Object” to get the value of the key , which would look like so:

hash_name.hash_key —-> hash_value

The semicolon (;) :

Semicolons are not obligitory in Ruby , in fact they are not an option at all there are no semicolons where there is a statement in ruby.

However in javascript Semicolons are necessary where there is more than 1 statement on a line. However do not use them after a curly bracket

While loops:

Ruby while loops are also relatively less cumbersome than Javascript while loops.

while (x < 10) #actions x +=1end

Within Javascript we can see much more semicolons and also a tonne more curly brackets of all kinds. In addition the incrementing by +1 is different in Ruby , where it just takes you having to increase it by +=1 .

while (x<10){ //actions;x++;}

Functions:

Functions in Javascript are known as reference types so essentially If I were to go ahead and call a function by saying

function sayhello(name) {return “ Helllo “ + name}

where as in Ruby functions are defined like so

def sayhello(name) p “Hello” + name.to_send

Usage Differences

To start out Javascript is in a large majority of websites nowadays, being famed for creating interactive features within the browser, although it may not be the most powerful language or performant.