/TASK-DAY4

Today's task involves solving problems using different types of functions in javascript

Primary LanguageJavaScript

TASK-DAY 4

Today's task revolves around functions and it's types.
Generally in Js thare are four different types of functions:

  • Named functions
  • Anonymous functions
  • Arrow functions
  • IIFE - Immediately Invoked Function Expression

Question 1

Question 1 requires solving the given problem two ways

  1. Anonymous function
  2. IIFE

syntax for Anonymous function:

let result = function(params) {
    //statements
    return value;
};

console.log(result(arguments))

syntax for IIFE:

let result = (function(params){
    //statements
    return value;
})(arguments);

console.log(result)

note: the function inside the IIFE can be of any type that doesn't change the fact that it's a IIF expression

The difference between above two is that IIFE can be run only once and cannot be reused as a function block
where as, anonymous function can be used again and again but can be acces through the variable and not a function name

Question 2:

Question 2 requires to solve the problem such that functions are Arrow functions.

syntax for Arrow functions

let result = (params) => {
    //statements
    return value;
}