Here is my code, I am working on a Node.js application, I would like to define a variable inside a function then be able to use its value out side the function too, how can I achieve this?
var readline = require('readline');
var rl = readline.createInterface(process.stdin, process.stdout);
rl.setPrompt('guess> ');
rl.prompt();
rl.on('line', function (line) {
inputl = line; //I belive not using Var makes the variable Global? am
am I correct in thinking so?
if (line === "correct")
console.log('correct answer my freind.')//rl.close();
if (line === 'quit')
rl.close();
rl.prompt();
}).on('close', function () {
process.exit(0);
});
{
console.log(inputl);
}
Thank you for your help, I have switched to sync.prompt, which has now fixed the issue. Your answers did help in my understanding of js, so they did serve a purpose.