# Typescript

### Optional Parameters

Use a question mark (`?`) for optional parameters.

```typescript
function greetWithTitle(title: string, name?: string): string {
   return `Hello, ${title}${name ? ' ' + name : ''}!`;
}
```

### Arrow Functions

Arrow functions are concise. For a single statement, you can omit curly braces:

```typescript
const add = (a: number, b: number): number => a + b;
```

## Array Methods: `forEach`, `map`, and `filter`

### The `forEach` Method

Iterate over array elements easily.

```typescript
let fruits: string[] = ["banana", "mango", "apple", "cherry"];
fruits.forEach((fruit) => console.log(fruit));
```

### The `map` Method

Create a new array by applying a function to each element.

```typescript
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map((num) => num * 2);

console.log(doubled); // Output: [2, 4, 6, 8, 10]
```

### The `filter` Method

Create a new array containing elements that pass a test.

```typescript
const ages = [15, 20, 17, 30, 14];
const adults = ages.filter((age) => age >= 18);

console.log(adults); // Output: [20, 30]
```
