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

118
Vistas
How do you pass unknown amount of variables into a function in Javascript

I am new to programming, as far as I know, we can pass variables into a function, let's say I can calculate the total price of a product by multiply the quantity and unit price.

const calculatePrice =(quantity,unitPrice)=>{
  let totalPrice=quantity*unitPrice;
  console.log(totalPrice)
  return totalPrice;
}

so I can use the above function to calculate the the total price by doing calculatePrice(2,3.5),so this will give me an answer of 7.

But what if I want to insert two items or three items (unsure amount)? for example,I want to get the the sum of 2*3.5 and 3*4.8 how do I implement this?

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

0

Functions are first class citizens in javascript, meaning your can use them where you'd use a variable. So, you can add their result as well.

var sumOfPrices = calculatePrice(2,3.5) + calculatePrice(3,4.8);
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