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

853
Views
Javascript - Is it possible to put 2 values into 1 parameter of a function?

Example:

const exampleFunq = function (exampleParameter, exampleParameterTwo) {

} 

Now when i invoke it, let's say i want to put 2 values into 2nd parameter;

exampleFunq(1, 2 3)

i know this code is wrong but is it a possible concept?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

JavaScript doesn't have tuples as language concept, but you can always pass an array or an object:

function example (arg1, arg2) {
  console.log(arg1, arg2[0], arg2[1])
}

example(123, [456, 789])
function example (arg1, arg2) {
  console.log(arg1, arg2.first, arg2.second)
}

example(123, { first: 456, second: 789 })

Using destructuring, you can make this seamless, if so desired:

function example (arg1, [arg2A, arg2B]) {
  console.log(arg1, arg2A, arg2B)
}

example(123, [456, 789])
function example (arg1, { first, second }) {
  console.log(arg1, first, second)
}

example(123, { first: 456, second: 789 })
about 4 years ago · Juan Pablo Isaza Report

0

You could treat your 2nd (and 3rd, nth...) param as variable list of arguments.

const exampleFunq = (exampleParameter, ...additionalExampleParameters) => {
  console.log([exampleParameter, ...additionalExampleParameters]);
}

exampleFunq(1, 2)
exampleFunq(1, 2, 3)
.as-console-wrapper { top: 0; max-height: 100% !important; }

about 4 years ago · Juan Pablo Isaza Report
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!