How can I use modules in the browser, but also refer to variables and functions from within DevTools?

One way to make a variable accessable within DevTools is to create it on the window object:

// Variable in your module
var importantNumber = 1;

window.importantNumber = importantNumber;

This method works fine if you just have a couple of variables, but if you need to have access to a lot more variables within DevTools, I would recommend you go to the sources-tab in DevTools, search for your module and adding a breakpoint. When the execution pauses, you have access to all the variables within that module on the DevTools console.

Leave a Comment