There are two basic problems here:
test2
never exists
test2
is defined inside a function which is never called, so it is never defined.
The code would have to actually call the anonymous function it is inside.
However, assuming that is a side effect of you truncating the code for this question and in your real case that anonymous function does get called:
test2
isn't a global
So in order to access it, you need to be in the right scope.
The only way to do that for the console would be to:
- open up the sources tab of the browser's developer tools
- add a breakpoint inside the anonymous function
- run the code until your reach the breakpoint
- then use the console to access
test2
which is now in scope.
Note that given the structure of that code you might have to put the breakpoint before test2
has a value assigned to it and then step through the code until after it is defined.