Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List variables created in anonymous function

Tags:

javascript

If I have some Javascript code like the following...

(function(){
    var a = 'valueA';
    var b = 'valueB';
    var c = 'valueC';

    //Create a loop that prints the name of all variables created above
    for(var x in ?????){
        console.log(x);
    }
})();

How do I print out a list of the variables that have been declared and assigned inside the anonymous function.

like image 432
Mike Avatar asked Dec 23 '25 01:12

Mike


1 Answers

As mentioned above in a comment, it is not possible, as explained in this link Javascript Reflection

like image 199
Mike Avatar answered Dec 24 '25 15:12

Mike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!