9.
What is a valid statement about constants in JavaScript ES6?
Constants are automatically initialized with a value of undefined.
Constants, once declared, do not have a fixed value.
Constants are block-scoped variables.
Constants can be redeclared and updated.
Correct: C
In JavaScript ES6, a constant is a block-scoped variable, meaning it cannot be accessed from outside of the block it was declared in. Constants cannot be redeclared or updated, and they must be initialized at declaration.
function example() {
if (true) {
const localVar = 42; // 'const' is block-scoped
console.log(localVar); // Output: 42
}
// Attempting to access 'localVar' here would result in an error
// because it is not in scope outside of the block.
}
example();
// Attempting to access 'localVar' here would also result in an error.