Skip to content

Instantly share code, notes, and snippets.

@GusGA
Last active December 19, 2015 10:59
Show Gist options
  • Save GusGA/5944734 to your computer and use it in GitHub Desktop.
Save GusGA/5944734 to your computer and use it in GitHub Desktop.
3 ways to declare a function in javascript

###Using Function constructor

    var sum = new Function('a','b', 'return a + b;');
    alert(sum(10, 20)); //alerts 30

###Using Function declaration.

    function sum(a, b) 
    {
        return a + b;
    }
    alert(sum(10, 10)); //alerts 20;

###Function Expression

    var sum = function(a, b) { return a + b; }
    alert(sum(5, 5)); // alerts 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment