functionpow(x, y){let total =1;for(let i =0; i < y; i++){
total *= x;}return total;}
console.log(pow(3,3));letmyFunc=function(x, y){let total =1;for(let i =0; i < y; i++){
total *= x;}return total;}
console.log(myFunc(3,3));
{functionpow(x, y){let total =1;for(let i =0; i < y; i++){
total *= x;}return total;}let coolFunction =[pow];
console.log(coolFunction[0](3,3));let mathFunctions ={
power: pow
};
console.log(mathFunctions.power(3,3));
pow.description ="power of a number";
console.log(pow.description);functioncallbackExample(callback){returncallback(3,5);}
console.log(callbackExample(pow));}
4 memorizing
{
pow.caculated ={};functionpow(x, y){let stringVersion = x +"^"+ y;
console.log("string version: "+ stringVersion);if(stringVersion in pow.caculated){
console.log("found");return pow.caculated[stringVersion];}
console.log("caculating");let total =1;for(let i =0; i < y; i++){
total *= x;}
pow.caculated[stringVersion]= total;
console.log(pow.caculated);return total;}pow(3,3);pow(3,3);pow(3,5);pow(3,6);}
5 default
{functionpow(x, y,...extra){// default y = 2
console.log(extra);let total =1;for(let i =0; i < y; i++){
total *= x;}return total;}functionlargest(x,...extra){let largest = x;for(let i =0; i < extra.length; i++){if(extra[i]> largest){
largest = extra[i];}}return largest;}
console.log(largest(20,2,3,4,5,45));}
JS functions1 powerfunction pow(x, y){ let total = 1; for(let i = 0; i < y; i++){ total *= x; } return total;}console.log(pow(3, 3));let myFunc = function (x, y){ let total = 1; for(let i = 0; i < y; i++){