Immediately Invoked Function Expressions IIFE | chai aur

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

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

  • @Biradar_Ganesh
    @Biradar_Ganesh 7 месяцев назад +15

    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

  • @raosadaqat7302
    @raosadaqat7302 Месяц назад +4

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

  • @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

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

    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.

  • @ARPITCHOUDHARY1
    @ARPITCHOUDHARY1 9 месяцев назад +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.

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

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

  • @Adnan-td5iq
    @Adnan-td5iq 4 месяца назад +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 9 месяцев назад +4

    Best Lecture, understood everything, Thank you sir!

  • @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!

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

    Radhe Radhe ❤❤
    Thankyou sir for the amazing lecture.

  • @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.

  • @IqraMubeen.sheikh
    @IqraMubeen.sheikh Месяц назад +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 Год назад +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.

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

    Amazing concepts, I am learning a lot from your channel

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

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

  • @ChBilalMunir-y5z
    @ChBilalMunir-y5z 7 дней назад

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

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

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

  • @MuhammadYasir-cl4jp
    @MuhammadYasir-cl4jp 11 месяцев назад +2

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

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

      Thanks a ton 😊🙏

  • @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

  • @photosofmine3443
    @photosofmine3443 3 месяца назад +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 ;

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

    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

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

    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.

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

    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

  • @Poudel06
    @Poudel06 20 дней назад

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

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

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

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

      Thanks 🙏😊☕️

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

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

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

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

  • @AnkitKumar-xm1uu
    @AnkitKumar-xm1uu 18 дней назад

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

  • @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

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

    Thanks a lot Hitesh for such a wonderful explanation

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

    Wow i like your teaching style bhaiya!!

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

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

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

    Thank you so much for this simple explanation❤

  • @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 💌🙏

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

    sir ek he dil h kitni baar jitoge ❤❤

  • @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

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

    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

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

    Super duper work Hitesh bhai

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

    Thanks, your video is really time-saving!

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

    👆🏼 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)

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

    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 🔥🔥

  • @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 🎉😊

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

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

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

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

  • @hitendrasingh01
    @hitendrasingh01 11 месяцев назад +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.

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

    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")
    } )();

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

    Beautifully Explained

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

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

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

    Beautifully explained!

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

    A very well explained , thank you sir

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

    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

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

    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!

  • @shaileshthorat3928
    @shaileshthorat3928 10 дней назад

    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...

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

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

  • @pranjalgogoigaming-1209
    @pranjalgogoigaming-1209 10 месяцев назад

    PROVIDING EXTRA KNOWLEGE IS YOUR KEY FEATURE

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

    bade bhaiya dhanyavaad apka

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

    Nice explanation ❤

  • @VikashSingh-hc6zo
    @VikashSingh-hc6zo 11 месяцев назад

    thank you sir maja a gya great explanation and so intresting

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

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

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

    3:00 That's cooooool 🫨

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

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

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

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

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

    kaafi majedar tha ye video

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

    Thank you for that 2nd IIFE.

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

    Love the session

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

    Great content!

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

    Thanks A Lot 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?

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

    yar ap love ho

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

    Thank you sir !!

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

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

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

    Sir g thusi great ❤

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

    thanks,great one

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

    Great lecture

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

    GREAT PLAYLIST GOING ON ...

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

    Very nice content sir 💯💯💯💯

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

    Thank you so much sir❤❤❤

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

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

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

    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.

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

    Thank You Sir

  • @ashishgupta-gr5mq
    @ashishgupta-gr5mq 8 месяцев назад

    Namaste sir, now I got to why my compiler shows error while coding two iife before subscribe you 🎉

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

    Great One!

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

    Immediately invoked function expressions😊

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

    (function sum (num1,num2) {
    num1 + num2
    })(5,4);
    console.log(sum(5,8));
    Can't i use iife functions after they are declared

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

    Thank you

  • @AbhayGupta-ij6ji
    @AbhayGupta-ij6ji 5 месяцев назад

    sir, can't we pass object inside a function when we are dealing with IIFE?

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

    I have created Global variable const x and assign value 5
    and then created my iffe function and try to access that global variable but it is accessible in iffe function ?
    why ?
    you said sir it prevent it

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

    Sir front-end or back end developer ka future scope keya hai sir 🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔

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

    learnt new things

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

    Sir aik question hy woh yh k me ik CA finalist student ho pakistan sy coding or tech me bohot interest tha par kisi waja sy usko pursue ni kr paya pr ab JS seekh ra ho q k maza a ra hy is course me. Janna yh chahta ho iska use case kia ho skta hy mery lia

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

    what an explanation bhai!!

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

    thank you hitesh

  • @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.

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

    what is tge mening of global pollute sir 🤔 samjha nahi kaisey pollute kar dega

  • @MechanicalCoder-s3b
    @MechanicalCoder-s3b 3 месяца назад

    But when I am giving arrow function like this
    (let iife = () => {
    console.log("db connected agains");
    })();
    it shows me an error so why this error is coming .

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

    Thanks Sir!

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

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

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

    (let sum = function(){
    console.log(`hassan`);
    return sum
    })() IIFE use krty hovy hm variable mien value store ku nhi krwa skty ????????????????????????????????????

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

    Interesting topic