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

207
Views
What is the best way to write functions that does not use its parameter in JS?

Specifically, I am using react-semantic-ui's Select Form, which takes an onChange function. So I have defined my function as such:

const handleInputChange = function handleInputChange(event, data){// does something with data}

(don't mind the ugly syntax, that's airbnb style guide)

I am doing something with data, but I am not using the event parameter at all. What would be the best practice in this case, since it is generally a bad practice to declare a variable without using it?

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

0

You must declare a parameter for every argument before the one you want to use.

The idiomatic approach to marking a parameter as unused is to prefix its name with an underscore.

function handleInputChange(_event, data){

Some linters will recognise this and not emit a "unused variable" warning.

For example ESLint has a argsIgnorePattern option (but it also has a args option that lets you specify after-used).

about 4 years ago · Juan Pablo Isaza Report

0

Actually by using Js es6 you could code without unused argument:)

function handleInputChange(...[, data]) {
  console.log(data);
}

handleInputChange('event', 123);

And bellow is a similar question you could check out:) Standard conventions for indicating a function argument is unused in JavaScript

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!