Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

226
Vistas
Why is ( ) used instead of curly braces / brackets { } inside Javascript Map function?

Inside map function why is the function defined with ( ) => ( ) instead of ( ) => { }

  {mylist.map((elem, index) => (
            <div key={elem.id}>
              <h2>{elem.title}</h2>
            </div>
          ))}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can leave () out if you put everything in one line:

 {mylist.map((elem, index) => <div key={elem.id}><h2>{elem.title}</h2></div>)}

If you want to return something, but it take several lines, then you have to use ():

{mylist.map((elem, index) => (
    <div key={elem.id}>
        <h2>{elem.title}</h2>
    </div>
))}

Finally, when you want to perform something and THEN return the result, you need to use {}. You still need to care when you return something - if it takes several lines, you have to wrap it with():

{mylist.map((elem, index) => {
    const id = elem.id;
    const title = elem.title;
    return (
        <div key={id}>
            <h2>{title}</h2>
        </div>
    );
})}

For returning objects it's also a bit different: You can wrap your object into brackets: ({...}) or explicitly return it: () => { return { ... }}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda