Which of the following is the correct syntax for an arrow function?
Analysis & Theory
Arrow functions are written using the `() => {}` syntax.
What is the output of the following code?
```js
const add = (a, b) => a + b;
console.log(add(2, 3));
```
Analysis & Theory
`add(2, 3)` returns `5` because it's a valid arrow function returning the sum.
What is a major difference between arrow functions and regular functions?
A
Arrow functions are slower
B
Arrow functions do not bind their own `this`
C
Arrow functions must be named
D
Arrow functions cannot return values
Analysis & Theory
Arrow functions use lexical scoping and do **not** have their own `this`.
What will this code output?
```js
const obj = {
name: 'JS',
getName: () => this.name
};
console.log(obj.getName());
```
Analysis & Theory
`this` in arrow functions does not refer to `obj`, so `this.name` is `undefined`.
Can arrow functions be used as constructors (with `new`)?
Analysis & Theory
Arrow functions **cannot** be used as constructors and will throw an error if used with `new`.
Which of these is equivalent to `() => 'hello'`?
A
function() { return 'hello'; }
D
() => { return 'hello'; }
Analysis & Theory
Both `() => 'hello'` and `() => { return 'hello'; }` return the same value.
How do you write an arrow function with a single parameter `x` that returns `x * 2`?
Analysis & Theory
All listed formats are valid arrow functions returning `x * 2`.
Which of the following is **not true** about arrow functions?
A
They cannot be used with `this` in the same way as regular functions
B
They are shorter to write
C
They are hoisted like regular functions
D
They are useful in callbacks
Analysis & Theory
Arrow functions are **not hoisted** like regular functions.
What will this print?
```js
const fn = () => ({name: 'JS'});
console.log(fn());
```
Analysis & Theory
The object literal must be wrapped in `()` when returned directly from an arrow function.
What happens if you use `arguments` inside an arrow function?
B
It refers to the parent scope's arguments
D
It works the same as in regular functions
Analysis & Theory
`arguments` is not available in arrow functions — they inherit it from the parent scope.