If I have the following:
function hello(name, callback) {
var hello1 = "Hello There " + name;
callback(hello1);
}
hello("John", function(hello1) {
alert(hello1);
});
I can get “Hello There John” in an alert box. How do I make it such that I can have a hello2 variable so that there are two variables in the callback? I essentially want to do something like:
function hello(name, callback) {
var hello1 = "Hello There " + name;
var hello2 = "Greetings " + name;
callback(hello1, hello2);
}
hello("John", function(hello1, hello2) {
alert(hello1 + " " + hello2);
});
if you got only strings values, the best will be create a array:
then in the function you can put the values in the array:
and after that return the array:
and in the callback function you can get the values with:
or you can put make your own object (function) with some strings inside..and then return this function..But if you have only string values, better will be the Array.