Back to questions
JuniorTheoryCommon
What happens when the program runs?
const x = 1;
console.log(x);
x = 2;
console.log(x);1, then TypeError
- Expecting
1, then 2: aconstcannot get a new value. The linex = 2stops the program withTypeError: Assignment to constant variable.; useletfor a variable that changes. - Expecting only
TypeError: the assignment fails only when its line runs. Line 2 has already printed1by then.
- How would you change the program so that it prints
1 2without an error? - What does the program print if you remove line 3?