The transition of all transitions…

As my journey as a Flatiron School student soon comes to an end, I reflect back on all that I have learned thus far. Defining variables, writing methods, and passing in arguments all became second habit to me as learning to do so in Ruby was step one. I love Ruby, it’s to the point and with simple plain language you can create some pretty cool applications!

The only thing cooler than Ruby is adding the magic of JavaScript. (Insert dramatic music) So what is JavaScript?

JavaScript definition from https://www.google.com

Basically, JavaScript is the “sprinkles on top” of your application. HTML provides the structure or layout, while CSS is responsible for styling the page. Add some of the functionality of JavaScript and you will have a well styled, interactive web application. Similar to Ruby’s variables and methods, JavaScript also have a syntax for defining(declaring) variables and functions(methods). For instance, in the code snippet below, you will see that declaring variables in JS vs defining them in Ruby look very similar. However JS variables are used and “defined’ much differently.

#Ruby Methoddef greeting(name) 
print "Hi #{name}!, How are you?"
end
greeting(John) => "Hi John!, How are you?"#Ruby Variable name = "John"
greeting = "Hi!"
def say_hello(greeting,name)
print #{greeting}, #{name}
end

//JavaScript Function
function greeting(name) {
console.log(`Hi ${name}!, How are you?`)
}
greeting(John) => "Hi John!, How are you?"//JavaScript Variable let name = "John"
const greeting = "Hi!"

In order to take these variables and make them work for us, we need to build a function. A function, very similar to a method in Ruby, has a set of statements that will perform a task, determine a value or both. While the syntax is much different, if you break down each component, you will see how much functions and methods have in common. In Ruby ‘def’ and ‘end’ are mandatory as a method’s body, in JS, depending on the type of function, the syntax will most always look like this:

function greetUser(username) {
users.forEach(user => {
console.log(`Hi ${username}`)
}
// Curly braces are the 'def/end' in JS functions. And just as you have to call a method in Ruby, you have to 'invoke' or 'call' functions in JS.

There are many, many differences and similarities between Ruby and JavaScript, however understanding the uses of each language and what benefits they bring, allows developers freedom to create and build anything they want. Variables and Functions are the building blocks needed to develop a full functioning web application, as long as you have a solid foundation of each, all of the remaining differences become easy to navigate and learn.