Immediately Invoked Function Expressions IIFE | chai aur

Поделиться
HTML-код
  • Опубликовано: 27 ноя 2024

Комментарии • 197

  • @Biradar_Ganesh
    @Biradar_Ganesh 8 месяцев назад +17

    One unique thing that differentiates your Javascript series with rest all is the way you teach us best practices & important points with good examples rather than following the common procedure of just covering the basics which everyone does.
    Sharing important interview questions too

  • @Rajatsharma-dd1pf
    @Rajatsharma-dd1pf Год назад +63

    Immediately Invoked Function Expressions (IIFE): the secret sauce for encapsulating code and maintaining a clean global scope. In this video, you'll uncover the power of IIFEs and how they can enhance code organization, protect variables, and prevent naming collisions. Whether you're a seasoned developer or just starting out, understanding and utilizing IIFEs will level up your JavaScript skills. Get ready to dive into this transformative concept and supercharge your coding prowess!

  • @iamakashkumarram
    @iamakashkumarram Год назад +12

    Hanji, suntehi mann pura positive energy se bhar jata ha aur coding karneka mann karta ha. Thanks sir for this best JavaScript series.

  • @raosadaqat7302
    @raosadaqat7302 3 месяца назад +5

    Aap ka teaching ka andaz bohot acha laga. Aap ki wajah se JavaScript seekhna asaan aur interesting ho gaya hai. Shukriya!

  • @ARPITCHOUDHARY1
    @ARPITCHOUDHARY1 10 месяцев назад +4

    Never new this is called IIFE, though know this is an another way to call an function.. Thank you sir for such detailed videos.

  • @tech_channel110
    @tech_channel110 Год назад +8

    sir kamal kr ty ho ap
    bht achay sy or behtareen andaz may samjhaya ap nay
    big respect big respect for you

  • @harsh-alashi
    @harsh-alashi Год назад +4

    I took an Udemy Course wherein IIFE was explained for about 30-35 mins but I didn't understood a single word. Here things are much simpler to understand. Thank You Hitesh Sir!

  • @afaqkhatri968
    @afaqkhatri968 Год назад +4

    Awesome Way of teaching. By far best javaScript content on youtube.

  • @Adnan-td5iq
    @Adnan-td5iq 5 месяцев назад +2

    AWESOME SIR YOUR WAY OF TEACHING MAKES U TOTALLY DIFFERENT FROM OTHERS .THANKU SO MUCH SIR FOR UPLOADING SUCH A QUALITY CONTENT IN FREE

  • @shashankkumarpandey4184
    @shashankkumarpandey4184 10 месяцев назад +4

    Best Lecture, understood everything, Thank you sir!

  • @IqraMubeen.sheikh
    @IqraMubeen.sheikh 2 месяца назад +1

    (function() {
    console.log("Hello, Chai or code !");
    })();
    example:
    Tumne function banaya (function() { ... })
    Aur phir isko turant call kiya ()
    Yeh kaam kuch is tarah hota hai jaise tumne function ko likha aur pehle se hi keh diya ke “jaldi se chalo”!
    Iska fayda yeh hota hai ke tumhara function turant chalega aur apne kaam ke baad khatam ho jayega.

  • @tech_channel110
    @tech_channel110 Год назад +3

    I am profoundly awestruck and deeply appreciative of my teacher's (sir hitesh chodhary) exceptional ability to delve into the intricate nuances of JavaScript language concepts, elevating my comprehension to remarkable heights and leaving me utterly inspired.

  • @mr_professor_x
    @mr_professor_x 6 месяцев назад +3

    Radhe Radhe ❤❤
    Thankyou sir for the amazing lecture.

  • @abdulsaad8791
    @abdulsaad8791 Год назад

    Completely get it what's IIFE and most important is why we use it in real world scenario. Love your way of explaning topics.

  • @tech_channel110
    @tech_channel110 Год назад +4

    I am absolutely captivated by the way you masterfully unraveled the intricacies of JavaScript language concepts, infusing each lesson with a sense of wonder and leaving me both spellbound and incredibly grateful.

  • @photosofmine3443
    @photosofmine3443 4 месяца назад +1

    SUMMARY :
    1. IIFE is a function which immediately executes after it's creation . It is wriiten as one parentheses for wrapping the function and other for execution ()();
    2. Variables defined inside an IIFE are not accessible from outside its scope which helps to avoid conflicts with other variables or functions (global scope pollution). Means IIFE keeps variables and functions private in it.
    3. IIFE written with function name is named IIFE and not with name are unnamed/anonymous.
    4.We can use parameter inside first parentheses.
    5. To write two or multiple IIFE one should be end with semicolon ;

  • @Nova_The_Beyonder
    @Nova_The_Beyonder Год назад +1

    Your teaching skills are top notch, Thankyou for this great video.

  • @shoaib57847
    @shoaib57847 Год назад +1

    Hello sir hitesh im shoaib from karachi pakistan im learning javascript from your playlist its a awesome playlist thank you so much for this series

  • @ByteNinjas69
    @ByteNinjas69 Год назад +2

    Amazing concepts, I am learning a lot from your channel

  • @alanguagee
    @alanguagee 3 месяца назад

    sir you are rocking I missed my js class and i think thats great because I found you and learn more technical with ans than lecture;s without explanation theory.
    In earlier after py i hate js but after your lecture i m enjoying and writing so many codes in day and committing git too,
    thank you so much sir
    btw, current time is 12: 39 CST and I love it at midnight

  • @hitendrasingh01
    @hitendrasingh01 Год назад +4

    Full code + notes + Explanatory comment
    // Avoiding Global Scope Pollution:
    // Variables declared inside the IIFE are not added to the global scope. This helps in preventing naming conflicts with other scripts and libraries.
    // Encapsulation:
    // It allows encapsulation of variables. Variables declared inside the IIFE are not accessible from the outside, providing a level of privacy.
    // Isolation:
    // It helps in isolating code. Variables declared inside the IIFE do not interfere with variables in the outer scope, and vice versa.
    // Module Pattern:
    // IIFE is often used in creating a module pattern, allowing the creation of private and public methods within the same scope.
    // Avoiding Hoisting Issues:
    // By using a function expression, you avoid hoisting issues that can occur with function declarations.
    // Immediately Invoked Function Expression (IIFE) - Named IIFE
    (function chai() {
    console.log(`DB connected`);
    })();
    // Output: DB connected
    // If two IIFE are used, it's a good practice to end each with a semicolon to avoid potential issues.
    // Immediately Invoked Function Expression (IIFE) - Unnamed IIFE
    (
    (name) => {
    console.log(`DB connected ${name}`);
    }
    )('Postgres');
    // Output: DB connected Postgres
    // Explanation:
    // - The first IIFE is named 'chai' and logs "DB connected" immediately when the script runs.
    // - The second IIFE is unnamed and takes a parameter 'name', followed by the provided name ('Postgres').
    // - Both IIFE syntaxes are valid, and the use of parentheses around the function helps to indicate that it's a function expression being invoked immediately.
    // Note: Ending IIFE with semicolons is especially important when you are combining multiple JavaScript files into one, to prevent unexpected issues due to automatic semicolon insertion.

  • @aryantapre
    @aryantapre 11 месяцев назад +1

    Unbelievable content! Hats Off to Hitesh Sir 🙏🙏🙏🙏❤❤

    • @chaiaurcode
      @chaiaurcode  11 месяцев назад

      Thanks 🙏😊☕️

  • @MuhammadYasir-cl4jp
    @MuhammadYasir-cl4jp Год назад +2

    Sir your JavaScript playlist is top notch. Explaining the concepts very well and very easily.❤❤❤

  • @aquibrashid8815
    @aquibrashid8815 6 месяцев назад

    We need IIFE to deal with two things:
    1. To prevent any pollution to the global scope from the values inside our function - now, this holds true when working with the oudated var keyword or in instances where you mistakenly declare the functions and variables in the global scope instead of inside the intended function. If you take care of both these things, IIFE’s are not a strict requirement to prevent polluting the global scope.
    2. To call a function immediately - there can be instances where we need to immediately invoke a function but there can be other ways as well to immediately invoke the functions other than IIFEs.
    Overall , IIFEs are a good code practice to prevent any potential pollution problems in cases we are exporting our code to other files and also the code looks clean

  • @nidmcreativeart6079
    @nidmcreativeart6079 Год назад +1

    Absolutely right sir, these videos makes us confident. Because of this I can say, yes I know js from scratch 😊. Thanks alot sir.... Big appreciation from my side #madhubani, Bihar

  • @ChBilalMunir-y5z
    @ChBilalMunir-y5z Месяц назад

    Sir you are the best teacher.
    I have learnt a lot of js because of you.
    Thank you very much sir 😍

  • @Vikram_Singh_CS
    @Vikram_Singh_CS Год назад +1

    इस awesome content के लिए -
    धन्यवाद हितेश

  • @mehakkamran3929
    @mehakkamran3929 10 месяцев назад +1

    I was sick the whole week , now I'm back again and will complete the whole playlist IA.

  • @SuryaKarigar
    @SuryaKarigar Год назад +2

    It's a better practice to use ; after every expression ❤

  • @babarshabbir2554
    @babarshabbir2554 6 месяцев назад

    "Master IIFEs with this clear, concise tutorial! Ideal for JavaScript learners. #chai" - 9 words.

  • @Poudel06
    @Poudel06 Месяц назад

    best and simple explanation love from nepal ,aab ma chai pine laga hu ma

  • @Fantasticares
    @Fantasticares 3 месяца назад

    sir ek he dil h kitni baar jitoge ❤❤

  • @earlymorningcodes6100
    @earlymorningcodes6100 10 месяцев назад

    Thanks a lot Hitesh for such a wonderful explanation

  • @Jawad_khan6686
    @Jawad_khan6686 10 месяцев назад

    I don't know what is IIFE apki backend ki series dekh rha tha abhi tab main socha IIFE dekh lo phr ap ki ye video bhi dhondh li ❤
    Great Sir, Kmall ka teaching level hai 🔥🔥

  • @AnkitKumar-xm1uu
    @AnkitKumar-xm1uu Месяц назад

    Sir 🙏🙏🙏🙏🙏🙏ji bot achi chai banai hai maza aagya ❤

  • @psyyhill
    @psyyhill Год назад

    Really learning a lot from you, sir! Thanks for providing us this learning for free! 🙌🏻

  • @rahultripathi6935
    @rahultripathi6935 Год назад

    You always more than expectation ❤
    I be like itna depth me kon teach h
    Vo bhi chai ke sath

  • @fatimaiqra2169
    @fatimaiqra2169 6 месяцев назад

    Thanks, your video is really time-saving!

  • @safinkhan6329
    @safinkhan6329 7 месяцев назад

    Thank you so much for this simple explanation❤

  • @hamzasajid7973
    @hamzasajid7973 8 месяцев назад

    Super duper work Hitesh bhai

  • @zohaibalishah91
    @zohaibalishah91 4 месяца назад

    Sir border Paar Se Buht Sara Piyar Apke Liye...

  • @PijushKonar
    @PijushKonar 10 месяцев назад

    IIFEs are used in JavaScript for several reasons:
    Prevent global pollution: Variables and functions inside stay private, avoiding conflicts with other code.
    Create modules: Encapsulate code to organize and isolate functionality.
    Run code immediately: Useful for initialization tasks or ensuring execution on page load.
    Control `this` behavior: Bind `this` explicitly within the IIFE for specific scenarios.
    Think of IIFEs as self-contained bubbles for your code, keeping it tidy and organized!

  • @BitFire007
    @BitFire007 8 месяцев назад

    "Chai aur Code, you're the mentor every JavaScript learner dreams of. Phenomenal content!"

  • @mainakdasgupta7130
    @mainakdasgupta7130 4 месяца назад

    Wow i like your teaching style bhaiya!!

  • @codewithsehran
    @codewithsehran 7 месяцев назад

    3:00 That's cooooool 🫨

  • @rohitamrutkar7875
    @rohitamrutkar7875 Год назад +1

    First of all thank you sir to giving such a practical content to us please make Interview Base video on reacts and JavaScript 💌🙏

  • @pranjalgogoigaming-1209
    @pranjalgogoigaming-1209 Год назад

    PROVIDING EXTRA KNOWLEGE IS YOUR KEY FEATURE

  • @tusharpandita167
    @tusharpandita167 6 месяцев назад

    A very simple example given below
    // IIFE
    // example of named iife function
    (function HW(){
    console.log("Hello world")
    })();
    // example of unamed Iife function
    (() =>{
    console.log("Hello Universe")
    } )();

  • @ayush.tiwarios2105
    @ayush.tiwarios2105 4 месяца назад

    00:02 IF Immediately Invoked Function Expression in JavaScript
    00:57 Separate scopes are created to avoid pollution from the global scope
    01:50 Writing the function with the 'if' statement is easy but it is important to invoke the function immediately.
    02:43 Understanding the execution of functions and its impact on global scope pollution.
    03:37 Function written in the manner of Ara function causing an error
    04:41 Use semicolons to properly end lines of code
    05:34 Passing arguments to a function in JavaScript
    06:33 Naming conventions in IF statements

  • @palakjain7745
    @palakjain7745 Год назад

    Beautifully Explained

  • @Hammad-wp8dm
    @Hammad-wp8dm 4 месяца назад

    Lub you Sir g . #RUclips run this comment as IIfe function 😁😁😁. And donot forgot to use ; at the end of IIfe function

  • @mosin9708
    @mosin9708 6 месяцев назад

    00:02 IF Immediately Invoked Function Expression in JavaScript
    00:57 Separate scopes are created to avoid pollution from the global scope
    01:50 Writing the function with the 'if' statement is easy but it is important to invoke the function immediately.
    02:43 Understanding the execution of functions and its impact on global scope pollution.
    03:37 Function written in the manner of Ara function causing an error
    04:41 Use semicolons to properly end lines of code
    05:34 Passing arguments to a function in JavaScript
    06:33 Naming conventions in IF statements
    Crafted by Merlin AI.

  • @rahulsinghnegi4213
    @rahulsinghnegi4213 2 месяца назад

    If someone's IIFE not working try using this
    ; (function chai()
    {
    console.log(" DB Connected ")
    })();
    It is because Nodejs environment concatenate the previous line of code with the IIFE

  • @MohammedismailAkbarAli
    @MohammedismailAkbarAli 6 месяцев назад

    👆🏼 Quetion: Can an IIFE have a return value? No in normal case. But if someone stores it in a valiable it can be keept and reuse it.
    const result = (function() {
    return 10;
    })();
    console.log(result);
    (totally out of curiosity banged my head init this and i found this, thought to share with people)

  • @asadorakzaipti
    @asadorakzaipti Год назад

    A very well explained , thank you sir

  • @madhurikumari2071
    @madhurikumari2071 Год назад +2

    Such a content full learning .. #"full knowledge wasool "😊 this channel is so resourceful, if anybody wnna deep dive with Mern must go through this series and channel 🎉😊

  • @sumanthachark
    @sumanthachark Год назад

    Beautifully explained!

  • @kripashanker7201
    @kripashanker7201 3 месяца назад

    bade bhaiya dhanyavaad apka

  • @tech_channel110
    @tech_channel110 Год назад +3

    In light of your exceptional teaching, could you please point me towards the next enthralling video series that delves into the realm of Next.js ,React and typescript and database etc ? Your insights have been instrumental in shaping my understanding, and I'm genuinely excited to embark on this next phase of learning under your esteemed guidance.

    • @chaiaurcode
      @chaiaurcode  Год назад +3

      Check out my English Channel, Hitesh Choudhary.
      Such topics are covered there

  • @priyankagehlot9945
    @priyankagehlot9945 5 месяцев назад

    kaafi majedar tha ye video

  • @its_Amit_00
    @its_Amit_00 5 месяцев назад

    Nice explanation ❤

  • @saudjavaid566
    @saudjavaid566 5 месяцев назад +1

    yar ap love ho

  • @apoorvaraj3894
    @apoorvaraj3894 11 месяцев назад

    Thank you for that 2nd IIFE.

  • @VikashSingh-hc6zo
    @VikashSingh-hc6zo Год назад

    thank you sir maja a gya great explanation and so intresting

  • @hrushikeshmarathe5513
    @hrushikeshmarathe5513 Год назад

    Hi sir thanks for explaining such deep concepts.Waiting for react native episodes.Thanks in advance

  • @Manishkumar-kp5gr
    @Manishkumar-kp5gr 10 месяцев назад

    Immediately invoked function expressions😊

  • @aggsha7580
    @aggsha7580 3 месяца назад

    Thanks A Lot Sir ❤❤

  • @pankajpanday6351
    @pankajpanday6351 Год назад +1

    This is how global scope gets polluted
    var ex = "nagin"; // assume it is imported from library or written by other developer
    // some thousand line code
    if (true) { // we wrote this
    var ex = "good one"; // it broke the code below by modifying variable above
    console.log(ex);
    }
    // some thousand line code
    console.log(ex); // some other developer coded this
    and this is how IIFE prevents it
    var ex = "nagin"; // assume it is imported from library
    // some thousand line code
    (function () {
    if (true) {
    // we wrote this
    var ex = "good one"; // it broke the code below by modifying variable above
    console.log(ex);
    }
    })();
    // some thousand line code
    console.log(ex); // some other developer coded this
    A normal function can also do the same job but if we don't need that function again, we usually use IIFE.

  • @Whitefield123-f6w
    @Whitefield123-f6w 4 месяца назад

    Love the session

  • @mdrehanfarid2134
    @mdrehanfarid2134 Год назад

    GREAT PLAYLIST GOING ON ...

  • @talhakhan4684
    @talhakhan4684 Год назад

    Semicolon after IIFE
    We can also pass arguments to IIFE
    Named IIFE are IIFE function with name

  • @jinsishahcs7889
    @jinsishahcs7889 5 месяцев назад

    Great content!

  • @umairkhan5073
    @umairkhan5073 4 месяца назад

    Sir g thusi great ❤

  • @priyalss2910
    @priyalss2910 Год назад

    Very nice content sir 💯💯💯💯

  • @word_wide_fukrey
    @word_wide_fukrey Год назад +1

    Sir, how IIFE and normal function different in case of polluting globle scope, as far as i know, i think normal function are aslo avoid polluting globle scope, so how can we differtiate IIFE and normal function in case of polluting globle scope?

  • @shaileshthorat3928
    @shaileshthorat3928 Месяц назад

    Sir it would have been better if aapne global variable declare krke uski value ko manipulate krke dikhaya hota inside the iife, that is something we dont want to happen if we're having the same variable name as of initially declared global variable ! Taaki aage jaakr joh global variable hai uski value change na ho...
    So in order to achieve that we will use var or let inside the iife with our variable name...

  • @swarnabbanerjee9102
    @swarnabbanerjee9102 9 месяцев назад

    Great lecture

  • @MonikaKumari-er4de
    @MonikaKumari-er4de 8 месяцев назад

    Thank you sir❤️

  • @jrahul42
    @jrahul42 3 месяца назад

    thanks,great one

  • @Sarvesh_Coder
    @Sarvesh_Coder Год назад

    poora clear hogaya, bach gaya interview

  • @Bca.Wallah
    @Bca.Wallah 8 месяцев назад

    Thank you so much sir❤❤❤

  • @squad4play
    @squad4play 8 месяцев назад

    Global scope mein kya pollution ho sakte hai , any practical scenario?

  • @arshitcc
    @arshitcc 8 месяцев назад

    Thank You Sir

  • @techgamerz498
    @techgamerz498 2 месяца назад

    // Immediately Invoked Function Expressions (IIFE)
    // IIFE = the secret sauce for encapsulating code and maintaining a clean global scope.
    // They can enhance code organization, protect variables, and prevent naming collisions.
    // It used for imediate invokation of function, we don't want pollution from global scope at all.
    // used --> while some time we want to coonect our DB and get that message.
    // ()() --> 1.() => For function defination, 2.() => For function call.
    (function chai(){
    // named IIFE
    console.log(`DB CONNECTED`); // DB CONNECTED
    })();
    // If you don't keep ";" Then this will give an error and the next function will not be executed.
    // Unnamed/simple IIFE with parameters and arguments
    ( (name) => {
    console.log(`DB CONNECTED TWO ${name}`); //DB CONNECTED TWO Krishnakunj
    } )('Krishnakunj')

  • @BLACKWIZX
    @BLACKWIZX 2 дня назад

    thank you sir

  • @mia_mia12456
    @mia_mia12456 7 месяцев назад

    iife used to protect function from global pollution

  • @neerajdhakad2858
    @neerajdhakad2858 7 месяцев назад

    Thank you

  • @ankushladani496
    @ankushladani496 Год назад

    Waiting for next lecture...❤

  • @torche6403
    @torche6403 10 месяцев назад

    Great One!

  • @krishnavamsi1126
    @krishnavamsi1126 6 месяцев назад

    learnt new things

  • @aritraganguly3957
    @aritraganguly3957 8 месяцев назад

    This was asked in TCS ninja interview

  • @swarajgaikwad2360
    @swarajgaikwad2360 Год назад +1

    @chaiaurcode - If we return some value in IIFE execution then where it will get stored?

  • @su1nta
    @su1nta 6 месяцев назад

    arrow functions with implicit return needs to be terminated with a semicolon too;
    faced a case where I defined an arrow function with implicit return and then defined an IIFE. but the IIFE didn't got invoked unless I terminated the arrow function. Hope that helps someone.

  • @manojnegi3502
    @manojnegi3502 11 месяцев назад

    thank you hitesh

  • @Instrumentation010
    @Instrumentation010 Год назад

    Interesting topic

  • @iamkmsyed
    @iamkmsyed 9 месяцев назад

    Thanks Sir!

  • @BABABENNETT
    @BABABENNETT 7 месяцев назад

    hitesh sir op

  • @KumarPiyushXIA
    @KumarPiyushXIA 6 месяцев назад

    thanks sir

  • @vishwamshah4509
    @vishwamshah4509 5 месяцев назад

    what an explanation bhai!!

  • @triptibhatnagar27
    @triptibhatnagar27 8 месяцев назад +1

    What is global scope pollution here ??