How get value of variable that has been optimized out?

czerny picture czerny · Jul 19, 2015 · Viewed 11.8k times · Source

Some variables can be "optimized out" during Javascript execution. Thus values of such variables are not available for inspection while debugging (User documentation). Variables view shows (optimized away) message and console throws following error if the variable is tried to be evaluated:

Error: variable has been optimized out

Is there any way to enforce evaluation of such variable or disable this optimization in Firefox?

Answer

Paul S. picture Paul S. · Jul 19, 2015

Use the variable in a way that prevents this optimisation.

function NOP() {}

// then in the optimised code

    NOP(myvar);
    // debugging here should now show `myvar`