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

113
Visualizações
Addition assignment null issue

Hi I'm getting an issue where the Addition assignment += is returning a null value and I'm not sure why this is. Here is an example of this circled in green:

enter image description here

Here is the code I'm working with:

    for (let i = 0; i < res.rowCount; i++) {
        let username = res.rows[i].user_id
        let level = res.rows[i].lvl
        let xp = res.rows[i].xp
        embed.description += `# ${i+1}. **${username}** **Level: ${level}** | **XP: ${xp}**\n`;}
        message.reply({ embeds: [embed]});
            
    

}

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

0

It sounds like embed.description has a null initial value, and concatenating to that will first "stringify" that value. Observe:

var foo = null;
foo += "test";
console.log(foo);

You can conditionally set embed.description before updating it, so if it's null make it an empty string:

embed.description = embed.description ?? '';

For example:

var foo = null;
foo = foo ?? '';
foo += "test";
console.log(foo);

about 4 years ago · Juan Pablo Isaza Relatório

0

It looks at the first loop iteration, embed.description is null, you concatenated null with a string which gives "null<string>".

var a = null;
a += "string";
console.log(a);

try setting blank/empty string to embed.description before for loop, like

embed.description = "";
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