functionmyfunction(){console.log("function");};myfunction()//Should say "function" in the console.functioncalculate(x, y, op){var answer;if( op ="add"){
answer = x + y;};elseif( op ="sub"){
answer = x - y;};elseif( op ="multi"){
answer = x * y;};elseif( op ="divide"){
answer = x / y;};else{
answer ="Error";};return answer;};console.log(calculate(15,3,"divide"));//Should say 5 in console.//I hope I helped!
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]);}}
/*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});