Require vs Import Javascript

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

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

  • @MonsterlessonsAcademy
    @MonsterlessonsAcademy  3 года назад +8

    WATCH NEXT: Javascript Interview Questions and Answers - Dominate Your Next Interview - ruclips.net/video/wnYKH2dO620/видео.htmlsi=5DfbGEfhXWiiv0a_

  • @souryavarenya
    @souryavarenya 3 года назад +53

    Ah man, one of the best videos explaining this. My understanding of distinguishing between frontend and backend JS cleared up after watching this.

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

    Almost every beginner JavaScript developer gets confused by this topic, But you made it very clear and easy, thank u Bro ❤❤

  • @kithowlett8374
    @kithowlett8374 3 года назад +17

    This is actually one of the best JS module explanation videos on RUclips - thank you!

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

    this should be pinned on top of the result list for any "beginner javascript tutorial" search. I have been working with JS without knowing this simple thing and had faced so many problems but never had that wise idea to actually search the difference between commonJS and ESM. Now I am humbled and unstuck. Thank you.

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

    Wow, everyone keeps saying es6 modules are better but rarely anyone tells why. Very precisely explained. I started exploring this topic after getting optimisation bailouts warnings in Angular for certain commonjs modules, I think now I know why commonjs modules are not tree shakable

  • @volkan8583
    @volkan8583 2 года назад

    Ty for good explanation. Its been 7 months of my journey and tutorials only say "do this" instead of why they do that in that way. You make clear some of the logic that Ive been misunderstood.

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

    One of the highly underrated channels on RUclips! Brilliant explanation!

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

    The best explanation abt this topic. Thanks.

  • @rameshwarprasad4722
    @rameshwarprasad4722 3 года назад +24

    This was such an amazing explanation man. You've literally covered every aspect of modules and that too in complete depth. Thank you soo much. Keep making more JavaScript videos.

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

    Your explanation is really good. Thanks for this video.

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

    Man you are the real MVP my guy, helping out plebs from the past. Thank you so much.

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

    You have just explained this topic in a very elegant way. Thanks for sharing this and spread your knowledge on the internet.

  • @wentinz
    @wentinz 2 года назад +6

    your video is so helpful! I love that you dive into the reason to invent modules before getting into how to use it, because for beginners, that is the hardest part to understand - why do we need to complicate things this way? Your explanation made perfect sense and I can see when we need to use it and when not!

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

    Explaining the 'why' made it extremely easy to understand! 👏 Thank you very much.

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

    Amazing explanation.

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

    I very rarely comment or participate on the Internet, as I'm usually just a passive listener and content reader. However, I felt compelled to break from my habits to thank you. Your explanation is splendid and incredibly well-done

  • @默-c1r
    @默-c1r 2 года назад +2

    Super helpful! I spent so much time watching different tutorials, but you explained this the best!

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

    Thanks for explaining the history behind this topic!!!!

  • @B-Billy
    @B-Billy 2 года назад

    I am Java developer learning JS. I was having a hard time understanding JS import.. Watched many videos but this is where it all make sence!! Kudos, thank you so much! Suubscribed.

  • @jesseneon1896
    @jesseneon1896 2 года назад +3

    I love the way you teach and code at the same time. Amazing video, I look forward to watching more of your videos.

  • @ashishbisht9162
    @ashishbisht9162 2 года назад

    This is the best simplified explaination i ever head .. so neat and clear......Thankx dude....Bless you...

  • @expertreviews1112
    @expertreviews1112 2 года назад

    THE best video on the topic... so much confusion with the evolution and this brings everything together !!!! awesome !! kudos

  • @GiuseppeGreco-jl7dx
    @GiuseppeGreco-jl7dx Год назад +1

    Clear and easy to follow, thanks. One step closer to understanding it all ✨

  • @panthonyy
    @panthonyy 2 года назад

    Wow, best commonjs modules and ES6 modules course on YT, that cleared a lot of things in my mind. Thanks a lot. You just got a new sub!

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

    your explanation is too good man i was writting Es6 module in Vuejs and Commonjs Modules in nodejs but didn't know there was difference in them until now those Udemy course don't teach this things even beeing most views and rated

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

    You are the best. I was confronting with the issue related to these require() import a lot of time. Hopefully, your video helped me to understand how to solve my issue. Thanks!

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

    Качественный материал. Теперь все понятно. Спасибо

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

    I was struggling with a code base that had "require" and exports.
    Whereas another codebase had import, it was super confusing.
    But thank you for clearing it up.
    Great video, good explanation.
    Also, you speak English very calmly, it helps me to understand better as I am a non-native English speaker.

  • @aakashjadhav327
    @aakashjadhav327 2 года назад +1

    nice video, very well explained, best video on this topic on the internet.

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

    Well explained and I understood it clearly. Kudos !

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

    I'm looking for this explanation a long time. Excellent presentation, congrats!

  • @gseven7307
    @gseven7307 2 года назад +1

    Too few likes for an amazing video like this. Very systematic, very clear and concise. Thank you very much

  • @Pareshbpatel
    @Pareshbpatel 2 года назад

    A very clear tutorial on CommonJS and JS Modules. Thank you.
    {2022-03-08}, {2023-12-14}
    PS Subscribed!

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

    Nice article. I learned a ton and watched it like ten times over two days! I have the timeline of modules, now.

  • @bhavyabansal1143
    @bhavyabansal1143 3 года назад

    One of the best videos I have seen so far... Thanks a lot for this.

  • @dylanmarais7304
    @dylanmarais7304 2 года назад +1

    Could you maybe do a video about your setup that allows you to so easily traverse through your files? Great content btw!

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  2 года назад

      Thank you! It is already there: ruclips.net/video/YrLiugDhCuk/видео.html

  • @IsaacLarbiOnline
    @IsaacLarbiOnline 2 года назад

    Thank you for such a clear and concise explanation.

  • @aminebelbahar1086
    @aminebelbahar1086 2 года назад

    Great content! all I wanted to know about node modules and es6 modules

  • @Sashad2003
    @Sashad2003 2 года назад +1

    You are one of the best teachers I know. Thank you very much for a lesson 😎👍

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

    Perfectly explained, thanks for the great content!!

  • @anselmleo4146
    @anselmleo4146 3 года назад

    Thanks so much for the in-depth explanation. Got here looking for how to refactor my common js code to typescript es6.

  • @CarlosChavez-ij5ki
    @CarlosChavez-ij5ki Год назад

    Damn, thanks man. I had a whole in my brain related to this topic. Now it is filled with a very good explanation.

  • @robertobenedit
    @robertobenedit 2 года назад

    Espectacular! increible lo claro que sos! Me diste un mejor punto de vista!

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

    Really clear explanation! Thanks so much!

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

      Glad it was helpful!

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

      @@MonsterlessonsAcademy I'm trying to store api key in self-made module and provides key using export/import; that works! However, it still reveals api key using browser devtool; is there any method to hide sensitive information in front-end code?

  • @exxzxxe
    @exxzxxe 2 года назад

    A first class presentation- well done!

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

    Amazing explanation of the topic. I understood everything. Also I would like to mention that if you are using the Live Server extension you don't need to install serve from the npm. Thank you for the tutorial :)

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

      You are welcome!

    • @0x007A
      @0x007A Год назад

      The text editor is either vim or one of its derivative clones such as neovim. Not everyone uses Microsoft Visual Studio Code.

  • @aliozeir708
    @aliozeir708 2 года назад

    very smooth and helpful. Thanks!

  • @Michael-sh1fb
    @Michael-sh1fb 3 года назад +1

    Thanks a lot. I've been putting off learning this because it's not a very interesting topic but you summed it up really well.

  • @farahrayis5928
    @farahrayis5928 2 года назад

    Clear explanation. Thank you very much. You saved me a lot of time.

  • @Untitled0078
    @Untitled0078 2 года назад

    I love the way he speaks.

  • @aimeerivers
    @aimeerivers 12 дней назад

    super helpful video, thank you so much!

  • @lukasluftlaufer1093
    @lukasluftlaufer1093 3 года назад

    So clear and concise! Thanks a Lot!

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

    Thank you so much! Very good explanation of the topic! 💛

  • @mrs8683
    @mrs8683 2 года назад

    just discovered your chanel and i am amazed how you explain thing, it is awesome, and i wonder what is the font you are using ? it is really dope

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

    Very clear explanation which covers a bit more than just the basics. Thank you. Did I understand correctly that ES6 modules can be used in NodeJS? Also wondering: what's the best way to use node modules in web extensions?

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

      In the latest versions of node both commonjs and es6 is supported but you must provide correct configuration to tell what module system you want
      nodejs.org/api/esm.html#modules-ecmascript-modules
      Regarding web extensions I have no idea

  • @hieuphanlong51
    @hieuphanlong51 3 года назад

    OMG, this is so easy to understand. Thank you very much.

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

    Great. Thanks for this monstrous explanation

  • @RishabhJain-uv7zj
    @RishabhJain-uv7zj 2 года назад

    This explanation was great. Can you make a video about the code editor you were using and some common shortcut you use it seemed pretty efficient while viewing this video.

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  2 года назад

      Hi, I already have a video about code editor
      ruclips.net/video/YrLiugDhCuk/видео.html
      90% of my shortcuts are standard vim shortcuts. They are not customised.
      dd - delete the line
      caw - replace the word
      ci( - replace in brackets
      dit - delete in tags
      etc, etc

  • @maxvhanamane840
    @maxvhanamane840 2 года назад

    It was a very thorough explanation, and it was really easy to understand ❤.

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

    Perfect explanation, thanks a lot

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

    perfect name for channel

  • @designniewolinsky7752
    @designniewolinsky7752 3 года назад +1

    Best video on that topic!

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

    so we just went a whole circle from *import from* to *const require* back to *import from* because we realized the original method is still the best one ?! now that's mindblowing

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

      No we don't. require was introduced in NodeJS from the start. imports were introduced much later in Ecmascript 6.

  • @ОлексійКудряшов
    @ОлексійКудряшов 2 года назад

    Great vid, really all you need in modules! thx

  • @amventures1
    @amventures1 2 года назад

    OMG! you cleared the confusion I had.

  • @scottisitt
    @scottisitt 2 года назад

    Very helpful! Thank you for explaining this!

  • @rsym.4397
    @rsym.4397 2 года назад

    the best explanation ever!

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

    Exactly what I was loking for; thanks. Subscribed gladly...

  • @mithunsurve
    @mithunsurve 2 года назад

    Best video on modules !!!

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

    Amazing!

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

      Thank you! Cheers!

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

      @@MonsterlessonsAcademy Возьмите меня в школу. Я бы за 3 месяца весь фул стек бы освоила, если бы у меня был бы такой учитель. Столько бестолковых учителей, которые сами знают лишь поверхностно. А хочется знать детали и что куда и откуда. Спасибо за отличные уроки.

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

    Cors errors drove me insane trying to learn react while learning new things outside of the framework

  • @952a259
    @952a259 Год назад

    Thank you for explanation!

  • @r.a.collection
    @r.a.collection Год назад

    Good discriptions well done 👍

  • @fernandogabriel8452
    @fernandogabriel8452 2 года назад

    Amazing content! You can really explain your stuff

  • @Technochoice-do1bl
    @Technochoice-do1bl 9 месяцев назад

    Thanks you made my day and save lots of mine time

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

    Just one IMPORTANT thing: 20:12
    Import statements are not hoisted, so you have to declare it at the top.
    (I went through several blogs and articles, may be I understood it wrong...in that case please correct me.)

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

      Import declarations are hoisted. In this case, that means that the identifiers the imports introduce are available in the entire module scope, and their side effects are produced before the rest of the module's code runs.
      developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

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

      @@MonsterlessonsAcademy Thanks for the reference...

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

      ​​@@MonsterlessonsAcademy Actually you are wrong about it, just try and run what you said it will not work as you explained in the video.
      .
      ES6 imports are hoisted to the top of the file, but they're in temporal zone until the actual import statement is evaluated...meaning You CAN NOT use the imported function or variable before the import statement itself.
      So basically the imports are hoisted but not like variable declarations.

  • @glurp1er
    @glurp1er 2 года назад

    Very good explanation, thanks!
    However, I'm used to OOP and I don't really get why I should switch to modules instead of keeping using classes.

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  2 года назад +1

      modules don't stop you to use classes.
      export default FooClass
      import FooClass from 'foo.class'
      you are done

    • @glurp1er
      @glurp1er 2 года назад

      @@MonsterlessonsAcademy Thanks for your quick response!
      I already use classes to organize my code in different files (sometimes static or singleton), so why should I use modules on top?
      I feel like I'm missing something...
      Maybe modules are a way to restrict the usage of a class to a specific file?

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  2 года назад +1

      @@glurp1er All your classes are global. Without modules you have name collisions, possibility to override class, etc.

    • @glurp1er
      @glurp1er 2 года назад

      @@MonsterlessonsAcademy Thanks again!
      Indeed I see now how modules could prevend classes names from colliding.

  • @hugobritotech
    @hugobritotech 3 года назад

    this is a true monster lesson, i learned several things, thanks for the content

  • @NN-si6cl
    @NN-si6cl 2 года назад

    Very helpful, thanks for the great breakdown!

  • @thebmusproject
    @thebmusproject 3 года назад

    Thanks for this great explanation!

  • @SanjeetKumar-xd3ne
    @SanjeetKumar-xd3ne 3 года назад

    This is awesome.
    Can you make a video on how modern web frameworks loads up works in the production version on browser, with all required packages and files, and how those files interact with other, that's a big challenge for me to understand.

  • @gurinderkaur6377
    @gurinderkaur6377 3 года назад

    Thank you so much for explaining in detail.

  • @Jeireme
    @Jeireme 3 года назад

    Thank you very much, everything is clear and very well explained!

  • @ercanyanmaz5624
    @ercanyanmaz5624 2 года назад

    Thanks for your great effort🙂

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

    Amazing video, thank you so much!

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

    great explanation

  • @HologramJay
    @HologramJay 3 года назад

    Holy cow, this was a superb explanation! Just one question, though. If I were to build a full stack application, would I need to use common.js for the backend and use es modules for the front end, or would you choose one type of module system for both ends? Thank you!

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  3 года назад +1

      Normally you want to use imports with webpack/babel on client and require on backend. However you might use imports on backend if you want with webpack/babel also but I don't like to do that.

    • @HologramJay
      @HologramJay 3 года назад

      @@MonsterlessonsAcademy okay, I see. Thank you for replying and thanks again for this video. It was really helpful.

  • @a_maxed_out_handle_of_30_chars

    Hello,
    thank you, the video is just too good, learned lot of things and the confusion was cleared
    i've few questions, at 19:28 "All imports must live on root level" what does it mean?
    what happens if I write the import statement at later point, let's say i've using a export function which is written on line 100, what if I write import statement of the exported function on line 99, will it work?
    will javascript refactor the code and put the import on the top of the file?
    thank you :)

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

      All imports will be moved to the top while reading. Imports in conditions won't work in comparison to require.

  • @n3d278
    @n3d278 2 года назад

    Just simply awesome.. 👏

  • @ltmutiwekuziwa
    @ltmutiwekuziwa 2 года назад

    So so clear. Thanks

  • @m12652
    @m12652 2 года назад

    Brilliant! Thank you

  • @murilo.g.t
    @murilo.g.t Год назад

    Nice video!! Thaanks!

  • @DevlogBill
    @DevlogBill 2 года назад

    Thank you for this quick lesson it was very helpful. I am fairly new to coding and the other day I looked at a piece of code and it seemed the page was filled with functions, am I correct to assume that most of a program is created using functions? I am only 2 months in learning JavaScript, so I am fairly new at this stuff.

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  2 года назад

      Hi, it's either functions which we exporting or classes which we exporting. We don't have anything else.

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

    I skimmed through the video searching for one specific difference that i didn't see you mentioning.
    I think that CommonJs modules give you copy of exported value while ES modules give reference to a value in scope of module. This makes closures with modules and cross module events possible.

  • @balajeemishra
    @balajeemishra 2 года назад

    Really,I have learned alot ❤️

  • @EdsonSilva-qr5gr
    @EdsonSilva-qr5gr 3 года назад

    Awesome content, keep going

  • @user-nh8ge6hx9r
    @user-nh8ge6hx9r 2 года назад

    thx for the clear explanation ;)

  • @कलयुग_कर्ण
    @कलयुग_कर्ण 2 года назад

    i am beginner in node.js which one i used import or require

  • @nelsoncaicedo6761
    @nelsoncaicedo6761 3 года назад

    Thanks man!! this is awesome