Hello, everyone!
How do I get the result from the block?
if (result.valid) {
const test = result.length_valid
} else {
console.log('...');
}
console.log(test)
CodePudding user response:
var test;
if (result.valid) {
test = result.length_valid;
} else {
console.log('...');
}
console.log(test)
CodePudding user response:
I think you should first check whether result.valid is true or false. Then, you should define "test" variable using let or var outside the "if" block. Variables declared/defined using const and let keywords are block-scoped and you can't get their values outside the block.
let test;
if (result.valid) {
test = result.length_valid
} else {
console.log('...');
}
console.log(test)