Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

43
Vistas
Are these 2 JavaScript statements equivalent?

These 2 statements seem to do the same thing.

const handleClick = () => alert('foo');

and

function handleClick() {
    alert('foo');
}

Are they identical and just syntactically different? The first one looks like a variable declaration, whereas the second one is clearly a function definition.

7 months ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

No, they are not the same thing. The arrow function has some limitations:

  • Does not have its own bindings to this or super, and should not be used as methods.
  • Does not have new.target keyword.
  • Not suitable for call, apply and bind methods, which generally rely on establishing a scope.
  • Can not be used as constructors.
  • Can not use yield, within its body.
7 months ago · Juan Pablo Isaza Denunciar

0

ES6 arrow functions provide you with an alternative way to write a shorter syntax compared to the function expression. There is no performance difference.

Are arrow functions faster (more performant, lighter) than ordinary standalone function declaration in v8?

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos