# Day 16/2

Plan 16/2:

* 8h-16h :  learning/practicing basic Js
* 16h\~ : customize speed

### Advanced function

* Functions are values, so that they could be saved as variables.

`const function1 = function greeting() { };`

`const function1 = function() { };    //this do the same thing`

`console.log(function1);   //log the function not its return value`

`function1();    //works just like calling for greeting()`

* Functions have a feature called Hoisting (function can be called before be created), however, function created through a variable doesnt have Hoisting
* Function can be used in Object or be the value for another function.
* <mark style="color:green;">`setTimeout(order, time);`</mark> is a built-in function to delay order an amount of time before working when it is called. Computer won't wait for the time goes up, the next line still work until the countdown ends
* <mark style="color:green;">`setInterval(order, time);`</mark> works like setTimeout and will work everytime the time ends
* <mark style="color:green;">`clearInterval(Id);`</mark> to stop interval. It needs an id that setInterval return which change everytime  setInterval runs, so the Id need to be declared outside the setInterval()
* <mark style="color:green;">`.forEach()`</mark> is used to loop through an array. A parameter is needed to reference to the item in array before running the function. Index is optional, it hold the index of the item

`[1, 2, 3].forEach(function(parameter, index) {});`

* `.addEventListener('event', function);` work just like `onclick=' ',` moreover, it can handle multiple event listener for one event
* `.removeEventListener('event', function);` remove an event listener from an event
* Use type='module' in \<script> to avoid name conflict among js files

  * delete the file that would be used as module
  * export the variable needed from that file

  `export const numbs = [];`

  * import that variable to module-type file

  `import {numbs as number} from ' ';   //'as number' is optional to change the name of variable`&#x20;
