10 - How to fix "Uncaught ReferenceError: Cannot access x before initialization" in JavaScript
The important bits
- Uncaught ReferenceError: Cannot access 'name' before initialization means that you intialized a variable with the const keyword, and you are trying to use that variable before it exists.
Exercise - Now you try it
Transcript
ReferenceError: Cannot access color before initialisation
what this means is two things: One we were using the const keyword to define a variable. In this case the variable color, and we are assigning it a value of red, and... Two: We are trying to access this variable before it was defined, so the solution here is that we have to move...
The color variable until after the definition
END and there you go. It works.