Question: I often need to monitor the contents of variables when testing programs like this:

```
var anObject = {aProperty:true}; // this is just an example.

console.log('anObject.aProperty: ' + anObject.aProperty);  <-- typed it twice.

```

I type the name of the variable into a string followed by typing the same thing again to reference the value.

It seems like an unnecessary duplication to write the same thing twice every time. Is there a way to do this by having to only write the name once using a function?

For example:

```
function show(value) {
  console.log("'" + ??? + "':" + value):
}  

```

so it can be used like this (or something similar):

```
   show(anObject.aProperty);

```

The above is just a simple example. Basically what I'm asking is whether there is a way to get the name of the variable that was passed into a function so that the name can then be output as part of a string showing the value of the variable.

Answer: 
Haters are gonna hate:

<http://jsfiddle.net/coma/6HTnB/>

```
var anObject = {
    aProperty: ['uno', 'dos', 'tres']
};

var log = function(object, property) {

    var evil = 'object.' + property;

    console.log(evil, eval(evil));
};

log(anObject, 'aProperty[2]');

```

Or even worse:

<http://jsfiddle.net/coma/6HTnB/2/>

```
var anObject = {
    aProperty: ['uno', 'dos', 'tres']
};

var show = function(a) {

    console.log(a + ':', eval(a));
};

show('anObject.aProperty[2]');

```

Well, eval is not evil per se, but the second approach is kind of ugly since the function needs to be in the correct scope.
Based on coma's answer, I think this may be the solution:

```
function show() {
    return function (value) {
        console.log(value + ':', eval(value));
    };
};

function aTest() {
   obj = {x:1, y:2};            show()('obj');
};

function bTest() {
   obj = {x:3, y:4};            show()('obj');
};

aTest(); // obj: { x: 1, y: 2 }
bTest(); // obj: { x: 3, y: 4 }

```