Can you reassign a new array or object to a variable declared with const?

  • Yes, always
  • Yes, but with restrictions
  • No, it will result in an error
  • Only if the variable is declared as a global constant
Variables declared with const cannot be reassigned to a new reference, whether it's an array, object, or any other data type. However, it's crucial to understand that this rule applies only to the reference itself, not the content of the variable. The content, if mutable (e.g., an object's properties), can still be modified.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *