JavaScript DOM Scripting By Example Improving the Application Code Next Steps

John Barhorst
John Barhorst
9,648 Points

DOMContentLoaded Event listener prevents accessing variables in the console?

I hadn't bothered to change the HTML and app back from earlier in the project. In trying to work out some things for these challenges, I was playing in the console and found that all my variables came back as undefined. I'm not sure why I thought to change back the event listener and the script tag location, but now that I have done that I can properly access my variables.

Anyone want to shed some light on this? Everything about the app was otherwise working properly, so I'd assume that meant the DOM was fully loaded, and thus the variables should exist. Is there some scope limitation to the event listeners that prevent it from working in console? Or some sort of extra step we need to work around if, out in the wild, we have to work under a situation like this?

Thanks for your time!

Steven Parker
Steven Parker
173,890 Points

To facilitate analysis of your issue, please show your code (properly formatted with Markdown) here. Or, you can make a snapshot of your workspace and post the link to it here.