Skip to content

Instantly share code, notes, and snippets.

@TalkativeTree
Last active December 18, 2015 03:39
Show Gist options
  • Save TalkativeTree/5719880 to your computer and use it in GitHub Desktop.
Save TalkativeTree/5719880 to your computer and use it in GitHub Desktop.

Javascript vs Ruby

JavaScript has two ways of defining functions – function expressions (FE) and function declarations (FD)

//function declaration:
    function functionName(){
      //the code you want to execute
      alert("This is a function declaration!")
    }
function expression:
    var aDifferentFunction = function(){
      //the code you want to execute
      alert("This is a function expression!")
    }

Example Functions: or if you want to get into too much detail http://benalman.com/news/2010/11/immediately-invoked-function-expression/

Everything in JS acts like an object

Array

[1,2,3].toString(); 
=> "1,2,3"

hash

({name: "Ben}).toString();  
    => "[object Object]"

Object

var ObjOne = function(){
  this.sayHi = console.log("hi")
  };
    =>undefined

myObj = new ObjOne(); => hi => ObjOne {sayHi: undefined}

myObj.toString(); => "[object Object]"

all objects inherit methods and properties from Object.prototype, but what is it?

callback: when a function gets passed to another function for future use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment