Functions review

Lets review functions!

function biggerOf(num1, num2) {
  if (num1 > num2) {
    return num1
  } else {
    return num2
  }
}

console.log(biggerOf(3, 20))
console.log(biggerOf(300, 20))
const biggerNum = biggerOf(23 * 4, 13 * 14))
console.log(biggerNum)

What happens if....

  • I don't have a return at all in the function?

  • I try to console.log(num1) outside the function? After the function? After the function is called?

  • What if I use const or let to create a variable inside the function?

  • How many parameters can I have?

  • What happens if I put some code after the return?

How do I return multiple bits of information from a function? Build this function:

The transform it into this function, returning an object:

Arrow functions

An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate limitations in usage:

Syntax

Now lets rewrite the above function as an arrow function

One more example, let write a function to multiply two numbers

Try rewriting functions you've using the arrow function syntax =>

References

Last updated

Was this helpful?