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

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

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 Relatório

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 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