Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRebecca Jensen
11,580 PointsEntering 'lastEvent' in the console does not return a list for me
In this tutorial, 'lastEvent' is set to equal 'e' inside of a function, and 'lastEvent' listed as a constant at the top of the code ('const lastEvent;'). The teacher then opens the project, clicks on the canvas we're working on, then enters 'lastEvent' in the console to get a whole list of possible events (or something like that).
When I type 'lastEvent', I get "Uncaught ReferenceError: lastEvent is not defined at <anonymous>:1:1 ...VM16494:1"
Snapshot of my workspace is here: https://w.trhou.se/md9qutdmqa
Relevant code here:
const lastEvent;
//On mouse events on canvas
$canvas.mousedown(function(e){
lastEvent = e;
});
Is something wrong in my code, or is this something browsers don't do anymore, or something else?
1 Answer
edinjusupovic
5,664 PointsVAR, LET and CONST are definitely not the same thing.
If you declare something with const, it will be immutable and cannot be modified; this is why when you declared lastEvent as a constant it didn't function as intended because in your code your function tries to overwrite lastEvent and this cannot be done with constant declarations.
Rebecca Jensen
11,580 PointsRebecca Jensen
11,580 PointsAha. The instructor was using var, but var is either const or let these days, and I used const. But if I use let, it works!