I want to know how I can get this variable from outside the function, maybe it seems something very simple, but I have not been able to do it. I need the TRADE_OUT data to be able to be used globally in the application, but I can only use it within that function that detects it, below I made a small "detect" to check if it obtained the bariable but the value never does not change,
I have the following code:
client.on("message", function(msg) {
const prefix = '#';
if (!msg.content.includes(prefix)) return;
const pattern = new RegExp(prefix + '([a-z]+)', 'i');
const getMatch = str => str.match(pattern)?.[1];
msg.channel.send(getMatch(msg.content));
var TRADE_OUT = getMatch(msg.content)
console.log(TRADE_OUT)
});
if(TRADE_OUT != undefined){
console.log(TRADE_OUT);
}else{
console.log("NOP")
}
How do I detect that new TRADE_OUT outside the function in nodejs or javascript?