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

185
Visualizações
Console.log Changes based on user input after being printed

I have this saga being called when opening a page with two console.log in to debug. This gives me two logs supposed to be similar. The values in data[0] is used in a AgGrid table. Two fields are editable in the table, these are null on the network call. However if i edit the fields in the browser, before expanding the console.log the value now shows as whatever i entered into the field. This will happen on either of the logs, so it can log the field as null first and then a value after.

function* saga({ Id }) {
    try {
        const response = yield call(get, GET_DATA(Id));
        console.log(response.data[0]);
        console.log(response.data[0]);
        yield put(fetchDataSuccess(response.data));
    } catch (error) {
        yield put(displayErrorMessage(NOB.ERROR));
    }
} 

Are console.log supposed to be able to change after being printed if what is references change? That would somewhat reduce how efficient it is for debugging.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

console.log() is effectively async, and if the value you are outputting is an object that changes shortly after you call console.log(), it is likely that what actually gets output will be the updated version.

So, short answer to your question, yes.

If you need to output it around the time of changing, there are two relatively easy means you can use to output it at that stage.

The first would be to simply output a clone. You can create a shallow clone like this:

const objectToOutput;
console.log({ ...objectToOutput });

If you need a deep clone, you could pull in a library or just write your own method.

The second option would be to convert it to JSON first. You could even then convert that JSON back to an object and output that if you want. Handy for complex objects that contain simple data (like you'd get from an API call):

const objectToOutput;
console.log(JSON.stringify(objectToOutput, null, 2));
// or
console.log(JSON.parse(JSON.stringify(objectToOutput)));
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