How to pass the variable from function ??
This is my function, I did the query and get the result successfully
I also confirmed that x=1 by console.log(x), So I can sure that x is set.
function checktype(x){
(Do something)
var x = rows[0].type; // [ RowDataPacket { type: 2 } ]
return x; //x=2
};
Here is the API part. I use the function checktype() here but I cannot get the returned value. I also try to run checktype(a); only but I cannot get the result / x too.
router.post("/check",function(req,res){
var a = req.body.a;
var result = checktype(a);
console.log(result); //undefined
});
var x = rows[0].type;, thetypeis real key forrows[0]? Also confused with});in thechecktypefunction, some typo?var x = rows[0].type;in the callback function right?