Posts

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

How we can return a specific element of an Array from function in JavaScript?

Image
 For outside array Steps: Step 1:   Define an array. For example, let’s define an array of Number               Step 2: Define a function that takes two parameters:   array and the index  Step 3: In this function,   array[index]   will return the element at the specified index in the array Step 4:  Call the function with the number ( original Array ) and the index of the element you want to return Another Method πŸ‘‡ For inside array click to : https://learningjavascript1.blogspot.com/2024/03/how-function-return-array-in-javascript.html

How function return an Array in JavaScript

Image
  How function return an Array in JavaScript πŸ‘‰  Array in function similarly work as Object in function. Here we will see normal syntax of Function & Array together πŸ‘‰Let access both array color[] and fruits[] Another way:  https://learningjavascript1.blogspot.com/2024/03/how-we-can-return-specific-element-of.html

How a function returns an Object Javascript

Image
  We saw how a function work step by step:   Function Data Flow Now we will learn how a function return an object in JavaScript πŸ‘‰ Let first define a function without parameter and create an object inside function body      and call it πŸ‘‰ Now we will call a function with parameter πŸ‘‰ Now store the returned value in - functionName () that include arguments ( " Pritam ", 30 ) for      further use & print it in console by console.log Note: rules should be added on 22 march  like parameters are variable and steps of function data flow and with object how its react

Function Data Flow

Image
How function work in JavaScript   Here is Default syntax of function: Steps: 1st: When we call the function with arguments(10,20), both arguments stored in  parameter (parameter1, parameter2                                                                 πŸ‘‡ 2nd: then it stored in function body where it called like we called both parameter with  return statement                                                                 πŸ‘‡ 3rd: when we use return  statement then the operation of parameter (here we sum both parameter) stored in function name(function_name)                           ...