Question: I want to call a function depending upon the data-value value of the `<a>` that is clicked. Is this possible? I tried `[call]();` and `call();`. Both return errors.

```js
function a() {
  alert("Hi");
}

function b() {
  alert("Bye");
}

$(function() {
  $("a").click(function() {
    var call = $(this).attr('data-value');
   [call]();
  });
});
```

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a data-value="a">A</a>
<a data-value="b">B</a>
```

Answer: 
You can call it from the `window` object.

> 
> The window object in HTML 5 references the current window and all items contained in it. Hence we can use it to run a function in a string along with parameters to the function.
> 
> 
> 

```
$(function(){
    $("a").click(function() {  
        var call = $(this).attr('data-value')
        window[call]();
    }); 
});

```

You can do it by using `eval()` too. ***But note, the `eval()` method is older and it is deprecated.***

```
$(function(){
    $("a").click(function() {  
        var call = $(this).attr('data-value')
        eval(call)();
    }); 
});

```
You should use the [`eval`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) function, which evaluates code represented as a string, *e.g.*:

```js
function a() {
  alert("Hi");
}

function b() {
  alert("Bye");
}

$(function() {
  $("a").click(function() {
    eval($(this).attr('data-value') + '()');
  });
});
```

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a data-value="a">A</a>
<a data-value="b">B</a>
```