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

129
Vistas
Why does this happen when I console.log a function in javascript?

when I console.log this function, why does it print 12 and undefined? Shouldn't it just be undefined as the function is not returning anything?

function area(w,h) {
console.log(w*h)
}

console.log(area (3,4))

EDIT: Sorry super new and I thought that regardless of what is printed by the console.log, the second console.log would receive only what the function returned.

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

0

function area(w,h) {
console.log(w*h) // Runs first and logs 12
}

console.log(area (3,4)) // Log undefined as the function doesn't return anything
about 4 years ago · Juan Pablo Isaza Denunciar

0

The area function is logging the area, which is where 12 comes from.

The second undefined is the output of the console.log itself.

Generally, when you run anything which does not have output in a REPL, JavaScript adds an extra undefined

about 4 years ago · Juan Pablo Isaza Denunciar

0

Because you already print it once

function area(w,h) {
  console.log(w*h)
}

area (3,4);

or

function area(w,h) {
  return (w*h)
}

console.log(area (3,4));

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