Question
// JavaScript console.log(Script has arrived); // Write code according to the comments below. console.log(-------------- First-Class Functions ---------------) // write a normal named function definition that
// JavaScript
console.log("Script has arrived");
// Write code according to the comments below.
console.log("-------------- First-Class Functions ---------------")
// write a normal named function definition that takes two numbers and returns the sum
function f(n1, n2)
{
return n1 + n2;
}
// declare a variable and assign it that function
let v = f;
console.log(f(8, 7) + v(15, 9));
// call the function through the variable and print the result
// write an anonymous version of the same function using the "function" syntax
// call it and print the result
let myFun = function(a, b, c)
{
return a + b - c;
}
myFun(1, 2 ,3);
// write a => version of the same function (still using {} and return)
// call it and print the result
let myFunc = (a, b ,c) => {return a + b + c; };
let myFunct = (a, b ,c) => a + b + c;
let acutal;
/* write a => version of the same function (with an expression body instead)
call it and print the result */
/* write a => function that takes a string and return another => function that prints that string
the internal function should *not* take the string as a parameter, since the variable is
already in scope */
//call the initial function to get the callback, then call that to print the string
// write and call a => function that takes a string and uses setTimeout to print that
// string 1000ms later
console.log("this script is done")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started