Language Comparison Chart

Ruby ES5 ES6
Variables num = 0 var num = 0; let num = 0;
const array = [];
String Interpolation p "Hello #{name}!" console.log("Hello " + name + "!"); console.log(`Hello ${name}!`);
Array Destructuring x, y = [1, 2] -- const [x, y] = [1, 2];
Object Destructuring -- -- const {x, z} = {x: 1, y: 2, z: 3};
Property Declaration hash = {x: x, y: y} var obj = {x: x, y: y}; const obj = {x, y};
Functions
def foo(arg1, arg2)
end
function foo(arg1, arg2) {
}


var foo = function(arg1, arg2) {
}
const foo = (arg1, arg2) => {
}
Default Arguments
def foo(arg = 0)
end
--
const foo = (arg = 0) => {
}
Multiple Arguments
def foo(*array)
end
function foo() {
var array = Array.prototype.slice.call(arguments);
}
const foo = (...array) => {
}
Classes
class Cat
def initialize(name)
@name = name
end

def meow
end
end
function Cat(name) {
this.name = name;
}

Cat.prototype.meow = function() {
}
class Cat {
constructor(name) {
this.name = name;
}

meow() {
}
}
Inheritance
class Animal
def initialize(name)
@name = name
end
end

class Dog < Animal
def initialize(name)
super(name)
end
end
function Animal(name) {
this.name = name;
}

function Dog(name) {
Animal.call(this, name);
}

Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
class Animal {
constructor(name) {
this.name = name;
}
}

class Dog extends Animal {
constructor(name) {
super(name);
}
}
Method Notation --
var obj = {
foo: function() {
}
}
const obj = {
foo() {
}
}
Importing require "byebug"

require_relative "game"
var Game = require("./game"); import Game from "./game";

import { view } from "./game_view";
Exporting -- module.exports = Game; export default Game;

export const view = () => {
}
Referencing Instance Methods (in text) Array#each Array.prototype.forEach() --
Referencing Class Methods (in text) Date::today Date.now() --