Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

366
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda