Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
How Can I Send The Parameter in Javascript Closures?

.I have a function called personAcc and want add income, when I don't use parameters in the functions inside the function, all the operations work fine but when I want to send a parameter, I cannot write a parameter in parentheses next to the function below. How can I use parameters inside closures?

    function personAccount() {
        let firstName='Mert', lastName='Kaya',  totalInc=0, totalExp=0, totalBalance=0
        const incomes =[1,3,5], expenses =[3,4,6]
        function totalIncomes() {
           totalInc=incomes.reduce((acc,num)=>acc+=num,0)   
           return totalInc
        }
        function totalExpenses() {
            totalExp=expenses.reduce((acc,num)=>acc+=num,0)
            return totalExp
        }
        function accBalance() {
            totalBalance=totalIncomes()-totalExpenses()
            return totalBalance
        }
        function accInfo() {
            return `He is ${firstName + ' ' + lastName}.\nHis total income is ${totalIncomes()} and total expense is ${totalExpenses()}\nHis total balance is ${accBalance()}`
        }
        function addIncome(...nums) {
           for(const num of nums) {
                incomes.push(num)
            }
            return incomes
         }
        return {
            totalIncomes:totalIncomes(),
            totalExpenses:totalExpenses(),
            accInfo:accInfo(),
            accBalance:accBalance(),
            addIncome:addIncome()
        }
    }


const personAccInfo=personAccount()

console.log(personAccInfo.totalExpenses)
console.log(personAccInfo.totalIncomes)
console.log(personAccInfo.accBalance)
console.log(personAccInfo.accInfo) 
console.log(personAccInfo.addIncome) // <= This 

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!