Posts

Showing posts from April, 2024

IIFE (Immediately Invoked Function Expression)

Image
  Normal syntax of IIFE πŸ‘‰ First add ( ) to a function then πŸ‘‰ Declare a empty ( ) πŸ‘‰as Arrow function When you want to use 2   IIFE then you have to add - ; ✅in the end of function declaration πŸ“ŒWithout adding in the end of a function declaration otherwise each function don't know where to stop Let add a parameter to it and call it πŸ“Œ here I add a parameter called name  then call with a argument- "Please" πŸ˜€ Its a named iife because I give a name to this function  i.e. chai πŸ˜†

Arrow function

Image
  Basic syntax of arrow function Implicit return: remove Curley braces { }                               remove return statement πŸ‘‰An implicit return is  a way of returning a value from a function without using the return keyword .  πŸ‘‰This can be done by using arrow functions, which have a shorthand syntax that allows you to omit the return keyword. πŸ‘‰ even you can add parenthesis ( ) in operation like: (a+b)             NOTE : If you wrap under { } then you have to write return statement Even you have to wrap a object under ( ) to print the object

This function

Image
  This function work in current block in a object If you want to print current context of a block by this function When you console.log (this) in function and again in calling then it shows an empty object(vs code) or window(a global variable) in browser N.B :-this not work under a function …not even in Arrow function it only work under object....you should try both and see what output you get