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.
setTimeout(order, time);
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 endssetInterval(order, time);
works like setTimeout and will work everytime the time endsclearInterval(Id);
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().forEach()
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 likeonclick=' ',
moreover, it can handle multiple event listener for one event.removeEventListener('event', function);
remove an event listener from an eventUse 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
Last updated