Ruby vs. JavaScript

Isaac Avilez
4 min readFeb 28, 2020

--

While Ruby is a back-end language, it can be supported by Ruby on Rails to support it’s full-stack language. As we know, JavaScript is a front-end language, but if supported with node.js(back-end), this will help it be a fully supported full-stack language. When it comes to front-end development, JavaScript is the way to go, there’s a reason it’s one of the most popular programming languages, and if not, the most popular. But, I want to talk more about the differences and similarities to both languages here. As many people tend to learn new languages, especially for full-stack software engineering, you’ll have to figure out the way that the computer can interpret the language you’re using. Both languages are object-oriented scripting languages, and both can create objects that can be manipulated by programmers.

Syntax Differences:

Syntactically speaking, variable declaration and assignment is more longer in JavaScript compared to Ruby. Here’s some examples that’ll be provided for you:

Declaration of a variable in JavaScript vs. Ruby:

Variable declaration in JavaScript.
Declaring a variable in Ruby.

In this scenario, both are fairly similar with the declaration of variables, except in JavaScript, you can declare it as a var/let/const as opposed to Ruby where you just name the variable without any prefix. Tip: JavaScript is stylized as camelCase, and is practiced to end your line of code with a “;”.

Creating a function in JavaScript vs. Ruby:

Function(method — ruby) being created in JavaScript.
Method being created in Ruby.

As we can see, both are creating functions, but both are syntactically different. In the JavaScript function, we have the function declaration -> functionName -> (parameters) -> { statement }. Inside the function is where the statement/block of code will be when ran. As opposed to JavaScript, Ruby methods are first declared with “def” -> method_name -> statement/block of code -> “end”. As we can see, both are just creating functions within your code, but both are syntactically different, and there’s more to write in JavaScript just to declare a function.

Creating an object/hash in JavaScript vs. Ruby:

Object declaration in Js.
Hash declaration in Ruby.

Both are very similar here, except that the hash in Js has a prefix of the declaration of a variable as opposed to Ruby where you can just name your hash, and store the key/values inside it. To call on a certain key inside the hash in Js, it’s followed as: hash_name.hash_key — > hash_value as opposed to Ruby where it’s followed syntactically as: hash_name[:hash_key] — > hash_value .

Documentation:

JavaScript has an extensive amount of documentation provided online for beginners/people transitioning into Js, and Ruby has an incredible amount of resources that are provided for you regarding documented information, and many online communities which are most active among open source frameworks. JavaScript also has an incredible amount of information that’s provided to you throughout many websites, has practice challenges, many free online courses to help further enhance your skills, and endless amounts of documentation regarding syntax. Both are used by several different companies, and those of which are very popular as well.

--

--

No responses yet