var x =myFunction(10,10);// Function is called, return value will end up in xfunctionmyFunction(a, b){return a * b;// Function returns the product of a and b}
functionworld(params){//Code to be executed when the function is called. }world()//Explaination//'world' in the function is the name of the function.//There are brackets after function name. Those are use to push parameters//The forth line Calls the function named 'world'
functionwalkTree(node){if(node ===null){return;}// do something with nodefor(let i =0; i < node.childNodes.length; i++){walkTree(node.childNodes[i]);}}
// NOTE : Function defined using (Function CONSTRUCTOR) does not // inherits any scope other than the GLOBAL SCOPEvar x=7;functionA(){var x=70;functionB(){console.log(x);// 70}letC=function(){console.log(x);// 70}letD=newFunction('console.log(x)');// user caps FB();// 70C();// 70D();// 7 - Inherits always the GLOBAL scope};A();
/*A function statement starts with the function keyword.
It can return a primitive type value, object, or another function.
For example, a function statement can return an object as shown in the following code example:*/functiongetProduct(){let product ={Id:1,Title:'Book',Price:30};return product;}let p1 =getProduct();console.log(p1);// prints product object
//(don't type behind the// type function to after that name it//functionname(){(name)=name
console.log(name)};//{ symbol is used o group together code but you must create n index/array of 2(array3)//
//! Button Click Event//! regular functiondocument.querySelector("button").addEventListener('click', handlClick);functionhandlClick(){alert("I got clicked!")//just to show it works//what to do when click detected}//!anonymous functiondocument.querySelector("button").addEventListener('click',functionhandlClick(){alert("I got clicked!")//just to show it works//what to do when click detected});