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

369
Visualizações
the code works with let but not with const. if i use a const the code will not work at all but i use var or let then the code works

the code works with let but not with const. if I use a constant the code will not work at all but I use variable or let then the code works.

let x, y, z;
   x = 10;
   y = 20;
   z = x + y;
   document.querySelector("#statement").innerHTML =
    "When you add the var x and y the value of z is " + z + ".";
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Consts need to be initialized, so const x, y, z won't work.

about 4 years ago · Juan Pablo Isaza Relatório

0

The const variables need to be initialized. So, your code would be:

const x = 10;
const y = 20
const z = x + y; // or just seriously assign 30 to it

document.querySelector("#statement").innerHTML =
    "When you add the var x and y the value of z is " + z + ".";

Also keep in mind that const variables cannot be reassigned.

If you want the variables' values to change, use var or let :

var x, y, z;

x = 10;
y = 20;
z = x + y;

document.querySelector("#statement").innerHTML =
    "When you add the var x and y the value of z is " + z + ".";
about 4 years ago · Juan Pablo Isaza Relatório

0

Consts need to be initialized

const x = 10 //work

const y //error
y = 20

and const is immutable

const x = 10
x = 10 // error
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