Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

115
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda