Skip to content

Instantly share code, notes, and snippets.

@iruslani
Created June 12, 2012 22:07
Show Gist options
  • Save iruslani/2920427 to your computer and use it in GitHub Desktop.
Save iruslani/2920427 to your computer and use it in GitHub Desktop.
Basic Javascript function Syntax.
// A simple function
var greet = function(person, greeting) {
var text = greeting + ', ' + person;
console.log(text);
};
greet('Iwan', 'Hello');
// A Function that returns a value
var greet = function(person, greeting) {
var text = greeting + ', ' + person;
return text;
};
console.log(greet('Iwan','hello'));
// A Function that returns another function
var greet = function(person, greeting) {
var text = greeting + ', ' + person;
return function() { console.log(text); };
};
var greeting = greet('Iwan', 'Hello');
greeting();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment