DEV Community

Cover image for 9 years on, I still google "javascript for loop"
Nočnica Mellifera for RudderStack

Posted on Edited on

9 years on, I still google "javascript for loop"

cover image by Libertinus Yomango

also despite writing Markdown every day for the last three years, I messed up the link above in v1 of this article

So, I'll admit it: sometimes I forget basic syntax. I think what gets me is the semicolons inside the parentheses. I feel like they should be commas? I don't know.

The point is that when I write for loops:

let str = '';

for (let i = 0; i < 9; i++) {
  str = str + i;
}
⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini ⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini

I always manage to mess up just enough that it's better to grab the syntax from the MDN than it is to write over again.

And really, it feels like a shameful admission but I don't feel embarrassed. H*ck I do stuff like this on my livestream and I don't think there's any reason that we shouldn't copy and paste basic syntax.

This is a place of honesty, take a moment to admit your not-so-shameful 'shameful secrets' about the reality of working in tech.

Top comments (29)

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
jenbutondevto profile image
Jen •

I usually let my IDE do that for me nowadays. typing "for" brings up an autofill for all the different ways to type a for loop, it saves a trip to my browser and back. No guarantees if I could type it from memory..!

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
paugramming profile image
Pau Riosa •

how do you that hehehe

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
jenbutondevto profile image
Jen •

It depends on which editor you're using. for webstorm (IntelliJ), by default can type

  • fori: for (let i = 0; i < ; i++) { }
  • forin: for (const item in arr)
  • and forof: for (const item of array) { }

typing "for" for brings up this tooltip, I can select with arrows and press tab for it to autocomplete. if you remember which template you want, you can just type eg "fori" + tab without waiting for the tooltip to show up.
auto complete

It's also similar in vscode. iirc, typing for will give you a bunch of options for the different iterators.

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini Thread
 
paugramming profile image
Pau Riosa •

nice thanks man! awesome

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini Thread
 
jenbutondevto profile image
Jen •

your IDE will have a bunch of different ones. worth having a look wherever they're located in for other useful ones :)

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
cklek profile image
Conrad Klek •

I would always delete robots.txt from whatever web boilerplate I was using. I didn’t know what it did and thought it was creepy

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
nocnica profile image
Nočnica Mellifera •
⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
devdufutur profile image
Rudy Nappée • • Edited

So don't use explicit loops 😅

new Array(10).fill(0)
  .map((elt, idx) => idx)
  .reduce((acc, elt) => acc + elt, "")
⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini ⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
eljayadobe profile image
Eljay-Adobe •

The best part of using this instead of a for loop: you'll never remember what you're supposed to search for on Google, so you'll be forced to memorize the pattern!

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
devdufutur profile image
Rudy Nappée •

Maybe this way of doing could seem a little overkill but has advantages :

  • No mutation
  • Each step in the pipeline of transformation is visible instantly
⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini Thread
 
eljayadobe profile image
Eljay-Adobe •

Not overkill in my book. I'm a fan of Elm and F# and Haskell. I think this kind of FP approach will supplant OO in time.

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
rinsama77 profile image
imrinzzzz •

I don't know if this is very relevant to the post, but I feel ashamed that I don't fit in with the stereotypical programmer geek. I'm one of the few women in my class who chose to pursue programming as a job after graduate. Most girls feel like they don't fit in, feel inferior, and chose to do other related work (e.g. product owner).

It wasn't really about gender, but it does play a role. What's most shameful is the fact that I'm not devoting all my time coding. I have other hobbies unrelated to programming (and photography, idk why but my "geek" friends tend to do these 2 things).

Most of the time I feel like I don't master this language/framework/tools enough to creatively and efficiently use it. That I'm not writing the most efficient code. I have this friend who likes to complain how people codes are bad (which I learnt from him a lot), and that put my confidence down lower than ever..

I'm trying to work on that, but it's exhausting sometimes not having people similar to you in the field or as a representative.

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
nocnica profile image
Nočnica Mellifera •

Coding has never been my hobby, and I've been super successful just by doing it at work. Those people who are looking at code 12 hours a day will, in all likelyhood, be burnt out in 5 years.

And keep in mind anyone questioning a new coder for their commitment is, i guarantee, insecure! Experienced devs confident in their skills don't question others.

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
rinsama77 profile image
imrinzzzz •

I see. Thank you so much! Also, seeing how you are confident to be yourself in this field has given me so much inspiration too!

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
kodekrash profile image
James Linden •

I think everyone does this. My kryptonite is 'this' in javascript. Sometimes, I go for weeks writing PHP only in (pick a) framework, and if I switch to 'vanilla' PHP, I have to google the simple things.

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
aarone4 profile image
Aaron Reese •

I write SQL, VBA, js, python and c#. Remembering the syntax difference is not worth the mental overhead when the internet will give you a copy paste answer in 30 seconds. What does wind me up though is the lack of wildcard consistency in the Microsoft stack.

  • In Access % in SQL ~ in Excel

Anyone got any other wildcards?

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
lorenzoblog profile image
Lorenzo •

Hey, where is the content?

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
nocnica profile image
Nočnica Mellifera •

This is a discussion post! I'm asking you and other readers to comment back :)

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
lorenzoblog profile image
Lorenzo •

Ok, sorry for the comments. I was hoping for an article about this, I would be interesting!

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
otumianempire profile image
Michael Otu •

I keep learning and relearning javascript over and over and over. I remember one time, it was a simple integration of a theme we bought for our dashboard. I was assigned the task of modifying one css class and ... it became the next three days css-ing. Respect to frontend developers.

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
rahoulb profile image
Rahoul Baruah •

It’s not shameful.

15 years writing Ruby code almost every day yet I still Google the Ruby CSV class at least once a week. It’s not even a complex class!

⚽ Live Match: rudderstack/ years on i still google javascript for loop add - Pertandingan Hari Ini
 
e99h2121 profile image
YAMADA Nobuko •

Same. When I write new class in my work, I try to find good template of my teammate.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.