JavaScript Loops - Code This, Not That

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 15. 01. 2019
  • Learn all about JavaScript loops đŸ€č and how to write code that maximizes performance and readability, while avoiding the bad stuff đŸ’©. fireship.io/snippets/javascri...
  • Věda a technologie

Komentáƙe • 408

  • @IAmLesleh
    @IAmLesleh Pƙed 5 lety +478

    Iterating over an object can be done with:
    for(const [key, value] of Object.entries(obj))

    • @Fireship
      @Fireship  Pƙed 5 lety +83

      Good call 👍

    • @ricardorien
      @ricardorien Pƙed 4 lety +5

      Do you know wich extension he used for emojis and show the console in one line?

    • @ghjerrr
      @ghjerrr Pƙed 4 lety +8

      Ricardo quokkajs quokkajs.com

    • @RocketTrolley
      @RocketTrolley Pƙed 4 lety +6

      I often use destructuring as well like this in loops. It just simplified things

    • @RocketTrolley
      @RocketTrolley Pƙed 4 lety +3

      Ricardo the tool you’re looking for is this quokkajs.com/ It’s called quokkajs

  • @hishammubarak3421
    @hishammubarak3421 Pƙed 5 lety +611

    This guy can pack a whole semester into 8 minutes. Watching this video was worth every second, I wish you uploaded one of these every week.

    • @LOOTS243
      @LOOTS243 Pƙed 5 lety

      đŸ€‘đŸ€‘

    • @hcmlopes
      @hcmlopes Pƙed 5 lety +12

      This is true. These videos are difficult to follow if you are new in the subject but if you are somewhat familiar with the topic they are great

    • @curiosdevcookie
      @curiosdevcookie Pƙed 4 lety +5

      I agree wholeheartedly ❀ I love learning, but the teacher is as important to the learning process as the knowledge itself, actually đŸ€”â€Š teachers are more important because they are our tool (no offence intended!) to digest any kind of knowledge by best breaking that down from his or her perspective.
      Sometimes their style jives with their students’, sometimes not, sometimes even that is a learning/adapting process which can offer a lot in itself 😏😎
      I deeply admire his expertise in so many areas and his teaching style, and yes, emoticons are included for sure đŸ˜đŸ€—

    • @gbenga9811
      @gbenga9811 Pƙed 4 lety

      I couldn't agree more. He's so good at it.

    • @maguilecutty
      @maguilecutty Pƙed 4 lety +2

      @@hcmlopes if you are new you should check out funfunfunction 's videos. Definitely a step before this and also really great teacher!

  • @Fireship
    @Fireship  Pƙed 5 lety +41

    RE 4:26 I was envisioning a long-running cpu intensive process as better suited for a compiled multi-threaded language. JS/Node is fast at basically every benchmark that matters, so didn't mean for that to come off the wrong way.

    • @olaorefouad2518
      @olaorefouad2518 Pƙed 5 lety +2

      Hi, Jeff. I was going through fireship.io, and I found out that you used web components via angular, Hugo for static content and firebase
      My question is; can you recommend any set of materials for to learn web components and Hugo.
      Please reply.

    • @Fireship
      @Fireship  Pƙed 5 lety +1

      @@olaorefouad2518 There is not much out there yet for WC. I made a video about "Advanced Angular Elements" recently that should be helpful if using Angular.

  • @carniattos
    @carniattos Pƙed 5 lety +29

    Even in basic videos like this I'm able to pick up some tips and tricks here and there. Magnificent work Jeff

    • @codeonmars579
      @codeonmars579 Pƙed 5 lety

      czcams.com/video/rXZT-u5T1qQ/video.html

  • @CaamSerenity
    @CaamSerenity Pƙed 4 lety +75

    One thing you need to keep in mind when using sort() on array though: So is destructive, unlike map(), filter() or reduce(). It changes the original array and returns a reference to that original array, NOT creating a new one!

    • @CST1992
      @CST1992 Pƙed 4 lety

      That should be expected, shouldn't it?

    • @natew4724
      @natew4724 Pƙed 3 lety +6

      @@CST1992 Not necessarily, because sort also returns a reference to the array like map, filter, etc.

    • @theclockworkcadaver7025
      @theclockworkcadaver7025 Pƙed 3 lety +8

      @@natew4724 Yeah. Ideally, methods which mutate the original data should return void - especially helpful in TS.

  • @amirhosseinrafiee2926
    @amirhosseinrafiee2926 Pƙed 5 lety +176

    Your videos are by far the best resource on programming . Keep up the good work đŸ‘đŸ»đŸ™đŸ»

  • @porgeet
    @porgeet Pƙed 4 lety

    Loving these videos, so clear and concise. This pleases me.

  • @SprHero
    @SprHero Pƙed 5 lety +26

    For the early birds where the video doesn't load: set the quality to 360p and then click somewhere on the timeline to skip a few seconds (you can go back to the beginning afterwards).

    • @filipcoja
      @filipcoja Pƙed 5 lety +5

      Actually works, thanks!

    • @Fireship
      @Fireship  Pƙed 5 lety +6

      Thank you Martijn! It won't even play for me.

    • @SprHero
      @SprHero Pƙed 5 lety +1

      @@Fireship No problem. I hope my quick solution worked for you as well. I enjoyed the video!

    • @valiok9880
      @valiok9880 Pƙed 5 lety

      Is it because of youtube compression ?

    • @SprHero
      @SprHero Pƙed 5 lety +2

      @@valiok9880 I'm not an expert, but I think you're right. I think youtube only had the 360p version ready, but for some reason gave us the HD option (which was not available). After setting the quality to that lower setting, skipping a few seconds forced youtube to load in the 360p quality (which was actually available). This way, the video could play.

  • @TheYuvelir
    @TheYuvelir Pƙed 3 lety +23

    what extension did you used to show these results interactively ?

  • @hdorodev
    @hdorodev Pƙed 5 lety +87

    I always wonder how can you do so much, with so much quality, with your time đŸ€”
    A video on your creative process, recording and editor set-up and your overall philosophical take on life, work and code would be very much appreaciated! You're quite the interesting human being :D

    • @Fireship
      @Fireship  Pƙed 5 lety +17

      Thanks for the unique suggestion. I will put all my tricks into a video one day. This sums up my philosophy on code fireship.io/mission/

    • @ChaoticNeutralMatt
      @ChaoticNeutralMatt Pƙed 3 lety

      @@Fireship that was actually interesting

  • @Poohbify
    @Poohbify Pƙed 5 lety +1

    100% want more of this, please and thank you!a
    It's great!

  • @javascript_developer
    @javascript_developer Pƙed 5 lety

    Great. Every time I watch your videos I feels like I am noob. But your videos are really awesome advancing my current knowledge.

  • @khai96x
    @khai96x Pƙed 5 lety +2

    Callbacks of sort() are supposed to return a number (-1, 0, +1), not a boolean. So you should've used `a < b ? -1 : +1` instead of just `a < b`.

  • @loveparmar1284
    @loveparmar1284 Pƙed 5 lety +1

    0 dislike !! This is the power of great content. Thank you sir!! Love from India.

  • @muradeliyev6291
    @muradeliyev6291 Pƙed 4 lety

    these types of videos are my favorite. please do more)

  • @saideepkonduri6429
    @saideepkonduri6429 Pƙed 5 lety +1

    Awesome as always , background music is
    👌

  • @christay9626
    @christay9626 Pƙed 5 lety +7

    I like all of your videos; they're all presented very nicely compared to other programming videos on CZcams. My only criticism is that the code is run through so quickly, so if you're a beginner its hard to keep up with what is going on...

  • @vidalroland
    @vidalroland Pƙed 5 lety +1

    Very good as always, Will be helpful to train

  • @vishalphilip6705
    @vishalphilip6705 Pƙed 5 lety

    We need more contents like this. 😍
    Performance Demo is lit đŸ”„

  • @rushabhsheth5441
    @rushabhsheth5441 Pƙed 5 lety +2

    I guess you must upload a complete big videos to master JavaScript for a mid user.
    This video was amazing keep the good work going !!

  • @sebbes333
    @sebbes333 Pƙed 3 lety +4

    You will ALWAYS get the best performance when you write "normal" code that the compiler will recognize, it is faster because the compiles does a LOT of optimizations that you probably never even have heard about, no mater how great coder you are.

  • @rezguibahaeddinne1605
    @rezguibahaeddinne1605 Pƙed 5 lety +2

    Just thank you so much, more please from this

  • @kingbeencent
    @kingbeencent Pƙed 5 lety

    I love your work dude!

  • @markgemmell3769
    @markgemmell3769 Pƙed 3 lety

    Excellent videos amigo. Well done.
    It is funny how the good old for loop is the fastest and IMHO the most explicit and easy to understand. 😄

    • @everyhandletaken
      @everyhandletaken Pƙed rokem

      It must depend on background, because all I see when I look at them is 1;-+++=>?#||.ÂŁii j-x= 1
      I honestly have no comprehension how that is easier to read (and notice that someone made a typo), than ‘x of y’.
      I’m happy to take the performance hit, for readability for myself.
      Not saying you are wrong by any means, just that I see it much differently â˜ș

  • @bgenp4f600
    @bgenp4f600 Pƙed 5 lety

    Hey great content, i've watched around 5 videos now and i was subscribed after the first one. The pace is a bit too fast though, at least for me that is. But pausing and going back to fully understand is really worth it.

  • @hnasr
    @hnasr Pƙed 5 lety

    Great work dude!

  • @amanimavu810
    @amanimavu810 Pƙed 5 lety

    Awesome stuff man, thanks a lot

  • @bencavenagh1036
    @bencavenagh1036 Pƙed 4 lety +16

    What is that plugin for displaying the console logs in the IDE? I would love that

    • @LuDaley
      @LuDaley Pƙed 4 lety +7

      It's probably the Quokka plugin(quokkajs.com/docs/). Made by the wallaby.js folks. I found it recently. I think it changed my life. Enjoy

    • @loobakaer2
      @loobakaer2 Pƙed 3 lety +1

      @@LuDaley And on this day sir, you've changed mine.

    • @victorlongon
      @victorlongon Pƙed 2 lety

      It is Quokka, wallaby uses it under the hood

  • @TimleyDegreeIII
    @TimleyDegreeIII Pƙed 5 lety

    You improved me a lot.

  • @kimdecastro6951
    @kimdecastro6951 Pƙed 5 lety

    You explained it well bro! đŸ™đŸ»

  • @shellwhale8994
    @shellwhale8994 Pƙed 4 lety +1

    What plugin do you use to show directly in the editor the console.log() output ?

  • @avatars24
    @avatars24 Pƙed 5 lety +1

    thnx for all the videos You make

  • @perc-ai
    @perc-ai Pƙed 5 lety

    one of the best js array vids on the internet lol

  • @_rathankumar
    @_rathankumar Pƙed 5 lety +1

    Nice content, is there any place where I can see your vscode setup?

  • @vlad981
    @vlad981 Pƙed 5 lety +5

    Btw, property order in object are also guaranteed to be chronological by ES6 specs.

    • @Fireship
      @Fireship  Pƙed 5 lety +3

      Good call. It's only guaranteed in certain cases, right? I don't think the for-in loop would be ordered in ES6

    • @vlad981
      @vlad981 Pƙed 5 lety +1

      If I understand it correctly - it must be guaranteed - 2ality.com/2015/10/property-traversal-order-es6.html

  • @enfieldli9296
    @enfieldli9296 Pƙed 2 lety

    The higher order function part is really conscise!

  •  Pƙed 4 lety

    what extension do you use to preview the console output and the variable value on hover?

  • @theatypicaldeveloper
    @theatypicaldeveloper Pƙed rokem

    Old but gold!

  • @The_Ghost_In_Heaven
    @The_Ghost_In_Heaven Pƙed 5 lety +4

    What editor are you using?

  • @pinkshortcomedy
    @pinkshortcomedy Pƙed 3 lety

    Its so *easy* to *understand!* thi deserves the most *likes in the world*

  • @umka7873
    @umka7873 Pƙed 5 lety +1

    Jeff, what the music played? Tell me pls

  • @loekaars
    @loekaars Pƙed 5 lety +2

    What extension / theme are you using for the green squares on edited lines?
    Edit: also how are you getting live console.log() output at the end of lines?

  •  Pƙed 4 lety

    What extension do you use which shows you the value of variables and errors at the end of the lines?

  • @RyanSmith-rb1ch
    @RyanSmith-rb1ch Pƙed rokem

    Good video. More please.

  • @maiconm
    @maiconm Pƙed 5 lety +1

    Great video! How do you make these emojis?

  • @REVENANT310
    @REVENANT310 Pƙed 2 lety

    What are you using that displays the console log results right next to the console log?

  • @leguminosa9
    @leguminosa9 Pƙed 3 lety

    what do you use? the compiler / plugin that has red and green thingy on the side, etc

  • @filipcoja
    @filipcoja Pƙed 5 lety +3

    The video doesn't load???

  • @vambach
    @vambach Pƙed 4 lety

    What is the vs theme that you use ? Also the configurations like plugins you have used. I like them.

  • @nickysalazar1418
    @nickysalazar1418 Pƙed 4 lety

    Excellent video, how do you do it? what program do you use

  • @blackpurple9163
    @blackpurple9163 Pƙed rokem

    What's that extension where the result/emojis print out right next to the statement inside the code, like next to the console.log( ) statement?

  • @TheRajeev7
    @TheRajeev7 Pƙed 5 lety

    @fireship can you tell me which IDE you are using.. how to get this info like suggestions pop ups when we code.. I'm using vs code.. and react tools ..
    I tried most of extensions .. nothing is good as Android IDE being from Android background.. plz help me out..

  • @NitinVarmaManthena
    @NitinVarmaManthena Pƙed 3 lety

    What plug-in are you using to display the in line debugger values?

  • @Punky_Brewmeister
    @Punky_Brewmeister Pƙed 4 lety

    Is there a certain extension you are using that shows the text out to the right of your code that evaluates the line?

  • @MakoNext
    @MakoNext Pƙed 4 lety

    which extension you use to show the output preview per line?

  • @Daw588
    @Daw588 Pƙed 5 lety +2

    What theme you using in Visual Studio VS Code?

    • @LazyGod840
      @LazyGod840 Pƙed 5 lety

      I'd guess it's the same theme that I use and it's called One Dark Pro.

  • @LOOTS243
    @LOOTS243 Pƙed 5 lety

    What addon do you use to see what is in the array?

  • @starlightromero1361
    @starlightromero1361 Pƙed 4 lety

    What is that plugin/package that allows the log to show up next to the code

  • @jashanbansal2613
    @jashanbansal2613 Pƙed 5 lety +2

    Jeff! You are awesome :)

  • @SarthikGarg
    @SarthikGarg Pƙed 4 lety

    What are the extensions and settings of your vscode

  • @marvinmokua
    @marvinmokua Pƙed 3 lety

    What extension are you using to display a run preview alongside the code that's to be executed
    emojis : đŸ€”đŸ€”

  • @manutzsong
    @manutzsong Pƙed 5 lety

    How did you get timer to show?

  • @RobertWildling
    @RobertWildling Pƙed 4 lety

    Since you use emojis so often, would there be any chance to do a video about those? E.g. the unicode space, how to insert them in VScode, your most favoured usecases...?

  • @BrianClincy
    @BrianClincy Pƙed 5 lety +3

    How do you get the emjoi's in your editor?

  • @HaiVu
    @HaiVu Pƙed 4 lety +1

    On NodeJS (latest at time of writing, on Ubuntu 19), for(let i = 0; i < ...) and for(x of y) and forEach() all gave roughly the same execution time, for a large array (1 million objs).

  • @KeplerEmeritus
    @KeplerEmeritus Pƙed 9 měsĂ­ci

    What is the extension called that shows the output of a line?

  • @djpunisha29
    @djpunisha29 Pƙed 5 lety +6

    p.s. I subscribed and smashed that notification bell :)

  • @ahmedferah9797
    @ahmedferah9797 Pƙed 3 lety

    whats you VS code extension for console.log( ) show automaticly plz ?

  • @justinjoker8060
    @justinjoker8060 Pƙed 2 lety

    so awesome channel. thanks bro

  • @brunoB182
    @brunoB182 Pƙed 5 lety

    What’s the name of this plugin that output console.log directly on vscode?

  • @hazemgharib
    @hazemgharib Pƙed 5 lety +3

    What kind of extension you are using for VS Code to display instant JS interpretation like that?

    • @ndcouch
      @ndcouch Pƙed 5 lety +6

      Quokka.js extension

    • @hazemgharib
      @hazemgharib Pƙed 5 lety

      @ndcouch Bless you man!

    • @ndcouch
      @ndcouch Pƙed 5 lety +1

      @@hazemgharib np buddy!

  • @JamieMcI
    @JamieMcI Pƙed 5 lety +75

    Much cleaner than my pooCount algorithms.

    • @Fireship
      @Fireship  Pƙed 5 lety +10

      Gotta keep the pooCount code clean

    • @codeonmars579
      @codeonmars579 Pƙed 5 lety

      czcams.com/video/rXZT-u5T1qQ/video.html

  • @acqzuel
    @acqzuel Pƙed 4 lety

    do you also do the graphics and motion design for your videos? or do you have a team or collaborator?

  • @agent-33
    @agent-33 Pƙed 3 lety

    Is this still good?
    Isn't the standard loop still the best to use when it comes to performance?
    Or may depend on a browser?

  • @gerritweiermann79
    @gerritweiermann79 Pƙed 5 lety +3

    I'm really loving your "Code This, Not That" series!
    You could have added generators because it's very similar to iterators ;)

  • @albert21994
    @albert21994 Pƙed 5 lety

    outstanding quality

  • @yogeshdeveloper5346
    @yogeshdeveloper5346 Pƙed 4 lety

    Which theme are you using for your vscode

  • @francesko1763
    @francesko1763 Pƙed 4 lety

    Which theme do you use in vs code ?

  • @ulrick90
    @ulrick90 Pƙed 4 lety +1

    How do you get emojis on the editor?? đŸ˜¶

  • @SlingShotKid007
    @SlingShotKid007 Pƙed 5 lety

    The quality of the production of these videos is fantastic, what kind of tools do you use for video editing, making the first emoji appear, etc?

    • @ricardorien
      @ricardorien Pƙed 4 lety

      You already know wich extension is? form emojis.

  • @boyemarc-antoine7027
    @boyemarc-antoine7027 Pƙed 3 lety

    learning so much new way to iterate that im asking myself: is it worth to learn of all those stuff cause they are not more efficient than the older lol waisting time to learn stuff only usable in JS where usual loopin way work same or better

  • @arkfish
    @arkfish Pƙed 3 lety

    What theme do you use for VSCode?

  • @williaamlarsson
    @williaamlarsson Pƙed 3 lety

    So much of this is similar to Haskell, I love it😍

  • @raulmartina8781
    @raulmartina8781 Pƙed 3 lety

    What was that Symbol.iterator? What use cases have symbols the docs are wierd? đŸ„ș

  • @VermaAman
    @VermaAman Pƙed 3 lety

    What are extensions you're using in your video? :l

  • @CST1992
    @CST1992 Pƙed 4 lety

    Also, slice and splice could be used to create a new Array from an existing one, if you're wanting to avoid mutating the existing one.

    • @domuuuuu
      @domuuuuu Pƙed 4 lety

      .splice() mutates, .slice() doesn't (returns a new array).

  • @aidarwm2393
    @aidarwm2393 Pƙed 5 lety +1

    Why I need to use 'for of' or 'forEach' if standard 'for (let i=0; i < arr.length; i++)' is more faster?

    • @Fireship
      @Fireship  Pƙed 5 lety +1

      You don't have to, it's just syntatic sugar to make your code easier to maintain and understand.

    • @jasonwismer2670
      @jasonwismer2670 Pƙed 4 lety

      Because coders get bored and want new toys. Too much syntactic suger isn't very good for you.

  • @himesh_89
    @himesh_89 Pƙed 5 lety

    how to artichect on firebase with real use case, say todoist app?

  • @perfect.stealth
    @perfect.stealth Pƙed 3 lety

    Why did i laugh at the spinning JS logo? I felt it was screaming event loop in my face 😂

  • @himynameisoleg
    @himynameisoleg Pƙed 4 lety

    Oh snap, finally an Array.reduce example that makes sense!

  • @redolentofmark
    @redolentofmark Pƙed 3 lety

    May I ask, what tools are you using to type so fast?

  • @sebcv8027
    @sebcv8027 Pƙed 4 lety

    What theme is he using during this video?

  • @ducodarling
    @ducodarling Pƙed 5 lety +5

    How can you make a video on looping without "while" loops?
    I'm sure it's faster than forEach(), and probably more than for(-of-)

    • @SandeepKumar-cx7cz
      @SandeepKumar-cx7cz Pƙed 3 lety +1

      he mentioned that if your priority is speed only, then you should probably not use js.
      in most of the projects these minor 8 millisecond not worth fighting for.
      readability and maintainability is also important.
      these milliseconds does not translate to end user experience.
      instead invest in good cdn and server bandwidth.
      think about it, async await is a syntactic sugar, you can do same with pure callbacks. which save some milliseconds. which one you choose, majority of the time.

    • @rafaelfigfigueiredo2988
      @rafaelfigfigueiredo2988 Pƙed 3 lety

      I should be wrong but shouldn't babel bundles write a script more machine friendly

  • @niclasj2871
    @niclasj2871 Pƙed 5 lety +1

    Nice video
    Something about the firebase admin sdk would be nice

  • @lulook2806
    @lulook2806 Pƙed 2 lety

    What JS IDE you use in this video?

  • @AkbaraliQ
    @AkbaraliQ Pƙed 4 lety

    what editor is it? and what theme is installed?

  • @capataina5087
    @capataina5087 Pƙed 4 lety

    which program and addons is he using while programming?

  • @fresch4395
    @fresch4395 Pƙed 5 lety

    Which texteditor is this? And what plugin do you need to display the output? Would make alot easier if I could see what the output will be without running it over and over again, looking for that console log and what not

    • @victorlongon
      @victorlongon Pƙed 2 lety

      He is using vs code and a plugin called Quokka

  • @ngundu86
    @ngundu86 Pƙed 5 lety

    What IDE are you using.

  • @sam.0021
    @sam.0021 Pƙed 5 lety

    which extension do you use for those sick green boxes?
    also, how did you type that blue (i assume commented) text just on the screen? was it video editing or another extension?

    • @Fireship
      @Fireship  Pƙed 5 lety +1

      It's all via Quokka, they also make a nice test runner called Wallaby.

    • @sam.0021
      @sam.0021 Pƙed 5 lety

      Fireship - AngularFirebase awesome thanks!