# Syntax

## Arrow Function

```javascript
const test = () => {
       ...
}
```

equal

```javascript
const test = function(){
       ...
}
```

## Rest Param & Spread Syntax (...)

### Rest Param&#x20;

* accept the numbers of argument as a array

```javascript
function myFun(a,  b, ...manyMoreArgs) {
  console.log("a", a)
  console.log("b", b)
  console.log("manyMoreArgs", manyMoreArgs)
}

myFun("one", "two", "three", "four", "five", "six")
// Console Output:
// a, one
// b, two
// manyMoreArgs, ["three", "four", "five", "six"]
```

### Spread Syntax

* Expand array into numbers of argument/ number
* Expand object into numbers of  key-value pair

```javascript
function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3];

console.log(sum(...numbers));
// expected output: 6

let numberStore = [0, 1, 2];
let newNumber = 12;
numberStore = [...numberStore, newNumber];
console.log(numberStore);
// [0, 1, 2, 12]

let obj = {test:1, test2:2};
let objClone = { ...obj , test3:3};
console.log(objClone);
// {test:1, test2:2, test3:3}

function test(...hi) {
  console.log(test);
}
test(1,2,3);
// [1,2,3]

```

## Destructing

```javascript
const student = { id:1, name:"Tom"};
const {id , name} = student;
console.log(id);
// 1
const array = [1, 2 , 3];
const [num1, , num3] = array;
console.log(num3);
// 3
```

## ?? vs ||

* ?? return next item when first item is undefined or null
* || includes 0 , false , empty string checking

```javascript
console.log(false ?? 1);
console.log("" ?? 1);
console.log(0 ?? 1);
console.log(null ?? 1);
console.log(undefined ?? 1);

// false
// ""
// 0
// null
// undefined

console.log(false || 1);
console.log("" || 1);
console.log(0 || 1);
console.log(null || 1);
console.log(undefined || 1);
// 1
// 1
// 1
// 1
// 1
```

## === vs ==



<pre class="language-javascript"><code class="lang-javascript">console.log(num === obj); // false
console.log(num === str); // false
<strong>console.log(obj === str); // false
</strong>console.log(1 === true); // false

console.log(num == obj); // true
console.log(num == str); // true
console.log(obj == str); // true
console.log(1 == true); // true
</code></pre>

* Better to use ===
