In the process of project development, if you are not careful when using variable declarations, you may cause type errors
such as:
Uncaught (in promise) TypeError: Assignment to constant variable. Uncaught (in promise) TypeError: Assignment to constant variable
.
Reason:
We use const to define the variable and there is an initial value. Assign a value to this variable later, so an error was reported.
The ES6 standard introduces a new keyword const to define constants. Both const and let have block-level scope:
The value of a constant defined by const cannot be modified, and the defined constant must be assigned an initial value;
let defines a variable, which can be assigned to a variable without initial value assignment.
This error is caused because we modified the constant. Although some browsers do not report an error, it has no effect!
Solution:
Change const to let to declare.
Similar Posts:
- How to Solve Const variable assignment Error
- [Solved] Lexical declaration cannot appear in a single-statement context
- Vue3’s use of reactive/torefs + V-model leads to the failure of response and the failure of El form input
- C++ error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m…
- Runtime error: invalid memory address or nil pointer dereference [How to Solve]
- [Solved] error: missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS
- TypeError: ‘Tensor‘ object does not support item assignment in TensorFlow
- [Solved] UnboundLocalError: local variable x referenced before assignment
- Linux: Environment Variables C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, CPATH Common Error [How to Solve]
- TypeError: Cannot read property ‘length’ of null