Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active November 14, 2018 22:03
Show Gist options
  • Save harrisonmalone/dd0db73c27b81aaf0cb8a0aedd09353f to your computer and use it in GitHub Desktop.
Save harrisonmalone/dd0db73c27b81aaf0cb8a0aedd09353f to your computer and use it in GitHub Desktop.

Function notations

Functions are all over javascript and they vary in form. This guide (and challenge) will help you with recognising the different function notations.

// declarative function
function add(x, y) {
    return x + y
}

// pointing to another function e.g. pointing to add
const myAdd = add

// variable with an anonymous function expression (as value)
const add = function() {
    return x + y
}

// arrow functions multiline
const add = (x, y) => {
    return x + y
}

// single line arrow functions
const add = (x, y) => x + y

// implicit return over multiple lines
const add = (x, y) => (
    x + y 
)

Challenge

Duplicate the above code but for multiply, divide, subtract

Be sure to test one at a time (since declaring something twice will break execution)

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