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

229
Vistas
Simple questions on javasript: socket.io and arrow function method () => {}

I'm currently studying basic javascript features, and I am quite struggling with the arrow function method. So I from what I've learnt, if there is only one parameter, it doesn't matter if we use parenthesis or not like the code below:

(singleParam) => { statements }
singleParam => { statements }

Then when emitting events in socket IO, to simplify the codes

// server-side
io.on("connection", (socket) => {
  socket.emit("hello", "world");
});

// client-side
socket.on("hello", (arg) => {
  console.log(arg); // world
});

could be simplified as

// server-side
io.on("connection", socket => {
  socket.emit("hello", "world");
});

// client-side
socket.on("hello", arg => {
  console.log(arg); // world
});

This is working fine in my project, thus I wonder the necessity of using parenthesis when using arrow method function. Maybe I'm not fully grasping the concepts, can anyone explain this method a little bit easier way? Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If using exactly one parameter in an arrow function you don't need to use the parenthesis. Some developers prefer to always add them however for consistency and readability.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

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