1. Function Declaration and Invocation:

2. Function Parameters and Arguments:

Arrow Functions:

Closure

A closure is formed when a function is defined within another function.

function outerFunction() {
    let outerVariable = 'I am from the outer function';
 
    function innerFunction() {
      console.log(outerVariable);
    }
  
    return innerFunction;
}
let closureExample = outerFunction();
closureExample(); // I am from the outer function

Different ways of creating functions in JavaScript

1. Function Declaration

A standard way to define a named function.

function greet(name) {
    return `Hello, ${name}!`;
}
console.log(greet("Dev Duo")); // Output: Hello, Dev Duo!

2. Function Expression