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

131
Vistas
How it's possible to have same variable and function name in JavaScript

We usually use React.memo as follow

const MyComponent = React.memo(function MyComponent(props) {
  /* render using props */
});

We have a MyComponent function and a MyComponent variable in the same scope, Why the syntax is correct and we have no runtime error like Uncaught SyntaxError: Identifier 'MyComponent' has already been declared?

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

0

Given a function declaration (you don't have one, this is for the sake of comparison):

function example() {
    ...
}

The identifier example does two distinct things.

  1. It sets the function name to example
  2. It creates a variable named example and assigns the function to it

It is important to distinguish between the name of a function and any variables that reference it.

You could go on to do:

const foo = example;

So now you have a function named example and two variables (foo and example) which can be used to access it.


The syntax you have in the question is a function expression not a function declaration.

One of the differences between function expressions and declarations is that the identifier only names the function. It does not create a variable of the same name. (Another difference is that the identifier for expressions is optional, you have a named function expression).

Since it doesn't create a variable, there is no conflict with const MyComponent.

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