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

189
Vistas
In which case the entire JavaScript file will be called?

I search on the Internet and it said that the difference between require and import is that require will call entire JS file. So in my situation, does entire module.js file will be called? And if it not, in which case that file will be called entirely ?

module.js

const a = 10;
const b = 20;
const c = 30;

module.exports = { a , b };

app.js:

const nums = require('./module');

console.log(nums);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Require is Non-lexical, it stays where they have put the file. It can be called at any time and place in the program.You can directly run the code with require statement.If you want to use require module then you have to save file with ‘.js’ extension.

Import is lexical, it gets sorted to the top of the file. It can’t be called conditionally, it always run in the beginning of the file.To run a program containing import statement you have to use experimental module feature flag.If you want to use import module then you have to save file with ‘.mjs’ extension.

about 4 years ago · Juan Pablo Isaza Denunciar

0

For some reason using the name module removed the code highlighting so I added the comments which fixed it....

In you example the entire module file is not loaded. And it is not correct to say that it can be. Module exports is not a file based module loader. Module functionality technically could be spread over many files. But, if you create a default and put everything in it that would be nearly the same thing.

(Assuming you are only using a single file to define your module.)

module.js

export const name = /** < **/ module /** name >**/;


export default  /** < **/ module /** name >**/;

You could then use named exports as before or using one of the import default syntax variations grab the entire file.

app.js

import /** < **/ module /** name> **/ from './modules.js';

or alternatively

import {default as /** < **/ module /** name> **/} from './modules.js';
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