Types of Function Declarations

// Function statement aka function declaration
function a(){
	console.log("a called");
}

// Function Expression
var b = function () {
	console.log("b called");
}

// anonymous Functions
function () {
	// this gives error
}

// Named function expression
var c = function x(){
	console.log("jsfs");
}
c(); // valid
x(); // ReferenceError: x not defined

// Difference between parameter & arguments
function f(param1, param2){
	console.log("f called")
}
f(argument1, argument2);

// First class functions
const fcf(function () {
	clg("passed")
}) {
	return function(){
		clg("return")
	}
}

what is a Callback functions

  • functions that are passed as argument in a function, is know as callback function.
function x() {}
x(function y() {}); // y is callback function

// example: Event Listeners and garbage collector

what is the difference between function statement and function expression

ANSWER : hoisting

  • Function statements are hoisted, meaning they can be called before they are defined in the code.
  • Function expressions are not hoisted, meaning they can only be called after they are defined.

what is first class functions/first class citizens

First-class functions (also known as first-class citizens) are functions that can be:

  • Passed as arguments to other functions.
  • Returned from other functions.
  • Assigned to variables.