Search code examples
javascriptfunctionarrow-functions

This simple function does not work. Why? I get "unexpected identifier" error


My train of thought to this function: I created an arrow function with 3 parameters and put it inside the const omg variable. This function should simply add up numbers 2, 3, 4, and I stored that into a random let sum variable. The result should be returned automatically.

const omg = (a, b, c) => let sum = a + b + c;

const lala = omg(2,3,4);
console.log(lala);

Solution

  • The problem is that you are not returning anything at the end of your function, u don't need the sum variable declaration:

    const omg = (a, b, c) => a + b + c;
    

    Here is a more verbose version of the fix:

    const omg = (a, b, c) => {
      const sum = a + b + c;
      return sum;
    };