Prepare for Angular Interviews with real-life questions. Utilize quizzes and examples to deepen understanding and enhance your skills. Gear up to ace your interview!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


How do you define a basic fat-arrow function?

  1. function add(a, b) { return a + b; }

  2. const add = (a, b) => a + b;

  3. const add = a, b => a + b;

  4. var add = (a, b) => { return a + b; };

The correct answer is: const add = (a, b) => a + b;

The correct way to define a basic fat-arrow function is using the syntax shown in the second choice. This syntax represents a concise way to create a function in JavaScript using the arrow function notation. In this case, `const add = (a, b) => a + b;` defines a function named `add` that takes two parameters, `a` and `b`, and directly returns their sum. The fat-arrow function allows for a more streamlined and clean syntax when defining functions, particularly when the function body consists of a single expression. The absence of curly braces and the implicit return when using a single expression are key characteristics of this style. Looking at other choices provides insight into what differentiates them from the correct answer. The first option uses the traditional function declaration syntax, which is valid but does not represent a fat-arrow function. The third option is syntactically incorrect because it fails to properly include parentheses around the parameters when using the arrow function syntax. The fourth option is functional, as it defines a fat-arrow function, but it includes curly braces and an explicit return statement, moving it away from the concise form that characterizes basic fat-arrow functions. Thus, the second choice exemplifies the essence of a basic fat-arrow