Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active September 6, 2023 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsee/c5640773e3691e2aa6ac6db27b5596bf to your computer and use it in GitHub Desktop.
Save mcsee/c5640773e3691e2aa6ac6db27b5596bf to your computer and use it in GitHub Desktop.
colors.forEach((color) => {
console.log(color);
});
// You use closures and arrow functions
@qm3ster
Copy link

qm3ster commented Jan 5, 2021

  1. You want to use of with iterators, in is for string keys of objects (including inherited).
  2. for in and for of syntax in js looks like for (const ident of expression)
    (where const could be let or var and of could be in)
  3. there's a missing ) in the last statement
  4. most commonly available print fn in js is console.log
  5. Array method is called forEach (capitalization)

so, all in all:

const colors = ['red', 'green']
const {log} = console

for (const color of colors)
  log(color)

// closure/arrow function
colors.forEach(color => log(color))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment