# Doubt in callback function

**URL:** <https://discourse.mozilla.org/t/doubt-in-callback-function/95878>\
**Category:** Learn\
**Created:** [April 13, 2022, 6:24am UTC](https://discourse.mozilla.org/t/doubt-in-callback-function/95878 "2022-04-13T06:24:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaishnavi\_A.N](https://avatars.discourse-cdn.com/v4/letter/v/13edae/32.png) [@vaishnavi\_A.N](https://discourse.mozilla.org/u/vaishnavi_A.N)\
**Post date:** [April 13, 2022, 6:24am UTC](https://discourse.mozilla.org/t/doubt-in-callback-function/95878/1 "2022-04-13T06:24:19Z")

</div>

function greeting(name) {  
alert('Hello ’ + name);  
}

function processUserInput(callback) {  
var name = prompt(‘Please enter your name.’);  
callback(name);  
}

processUserInput(greeting);

In the processUserInput(callback), does callback(name) refers to greeting(name)?

---

<div class="post-metadata">

**Author:** ![schalkneethling](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/schalkneethling/32/22691_2.png) [@schalkneethling](https://discourse.mozilla.org/u/schalkneethling)\
**Post date:** [April 13, 2022, 9:27am UTC](https://discourse.mozilla.org/t/doubt-in-callback-function/95878/2 "2022-04-13T09:27:25Z")

</div>

Hey there!

Yes, you are correct. Just be careful some of those single quotes in the code you posted are actually backticks(`) so, the code will not run. Here it is without those items fixed.

```
function greeting(name) {
  alert("Hello " + name);
}

function processUserInput(callback) {
  var name = prompt("Please enter your name.");
  callback(name);
}

processUserInput(greeting);

```

On which page did you get the code example?

---

<div class="post-metadata">

**Author:** ![vaishnavi\_A.N](https://avatars.discourse-cdn.com/v4/letter/v/13edae/32.png) [@vaishnavi\_A.N](https://discourse.mozilla.org/u/vaishnavi_A.N)\
**Post date:** [April 13, 2022, 10:57am UTC](https://discourse.mozilla.org/t/doubt-in-callback-function/95878/3 "2022-04-13T10:57:18Z")

</div>

If they are backticks, then also the code should run I suppose, because it will be the template literal.  
I just searched for ‘callback functions mdn’, it gave me the following page.

> **[Callback function - MDN Web Docs Glossary: Definitions of Web-related terms |...](https://developer.mozilla.org/en-US/docs/Glossary/Callback_function)**
>
> A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

---

<div class="post-metadata">

**Author:** ![schalkneethling](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/schalkneethling/32/22691_2.png) [@schalkneethling](https://discourse.mozilla.org/u/schalkneethling)\
**Post date:** [April 13, 2022, 11:16am UTC](https://discourse.mozilla.org/t/doubt-in-callback-function/95878/4 "2022-04-13T11:16:31Z")

</div>

Yes indeed. If they are both backticks it will work. However, unless you are doing string interpolation or creating tagged templates, I would recommend sticking with plain strings.

---

<div class="post-metadata">

**Author:** ![schalkneethling](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/schalkneethling/32/22691_2.png) [@schalkneethling](https://discourse.mozilla.org/u/schalkneethling)\
**Post date:** [April 13, 2022, 11:18am UTC](https://discourse.mozilla.org/t/doubt-in-callback-function/95878/5 "2022-04-13T11:18:24Z")

</div>

I see on that page it does use plain strings. Perhaps during copying it changed for some reason. Here is a Codepen with the running code as well: [https://codepen.io/schalkneethling/pen/mdpGxPo?editors=1111](https://codepen.io/schalkneethling/pen/mdpGxPo?editors=1111)

---

<div class="post-metadata">

**Author:** ![vaishnavi\_A.N](https://avatars.discourse-cdn.com/v4/letter/v/13edae/32.png) [@vaishnavi\_A.N](https://discourse.mozilla.org/u/vaishnavi_A.N)\
**Post date:** [April 13, 2022, 11:22am UTC](https://discourse.mozilla.org/t/doubt-in-callback-function/95878/6 "2022-04-13T11:22:47Z")

</div>

yes, thank u so much @schalkneethling

---

<div class="post-metadata">

**Author:** ![mikoMK](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mikomk/32/50456_2.png) [@mikoMK](https://discourse.mozilla.org/u/mikoMK)\
**Post date:** [April 13, 2022, 12:32pm UTC](https://discourse.mozilla.org/t/doubt-in-callback-function/95878/7 "2022-04-13T12:32:27Z")

</div>

> [@schalkneethling](#):
>
> Perhaps during copying it changed for some reason.

Yeah, that’s Discourse converting vertical quotes to typographical quotes in some situations when not using code fences.
