I have this function in JS:
function redGet(key){
var response;
red.get(key, function (err, reply) {
response = reply;
});
return response;
}
This keeps returning undefined on :
console.log(redGet("hello"));
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming that
red.get()is an AJAX-like asynchronous function, the problem is that you’re expecting it to operate synchronously. You won’t be able to get thereplyvalue until the asynchronous operation is complete, which means that anything that relies on this value must be invoked in the callback function.For example: