In a code review, you spot the line const arr = [10, 20, 30]; followed by arr = [40, 50, 60];. What will be the outcome when this code is executed?
- It will result in an error.
- The arr variable will now reference [40, 50, 60].
- The original array [10, 20, 30] will be modified.
- It will create a new variable arr with [40, 50, 60].
The code will result in an error. When you declare a variable using const, it cannot be reassigned to a different value or reference. Attempting to reassign arr to [40, 50, 60] will throw a "TypeError" because it violates the immutability of const variables.
Loading...
Related Quiz
- Which method is commonly used to change the text content of an HTML element using JavaScript?
- How do you ensure that dynamically added elements maintain accessibility features, like ARIA roles?
- You're debugging a JavaScript application and notice that a function defined within an object method using an arrow function is not behaving as expected. The "this" keyword is not referring to the object. What could be the reason for this?
- While working with React, you notice a function defined using the function keyword is not updating the component state as it should. You suspect it's related to the "this" keyword. What might be the problem?
- In JavaScript, variables declared with the var keyword have _________ scope.