Home > other >  how to stop passing value to next process?
how to stop passing value to next process?

Time:11-03

I'm new beginner in react-native and JavaScript here, i am using a if-else condition.

i want to check the first the condition is correct if it's correct then it will works in a different different function. Here is my codes:

const ab = true; 
let x;
if (ab === false){
    
// i want here to stop passing value of x;
//write a code so that x value can't be passed to console.log(x).

}
else if (ab=== true){
 x= [1,2,3]
}

console.log(x);

only when ab equals true, x value able to use. anyone can help me to write a codes for if statement where it will stop to passing values when the condition is correct.

Thanks for your trying in advance!

CodePudding user response:

I think it's impossible. by my experience.

CodePudding user response:

I'm also new beginner in JavaScript. maybe you can do like this:

let x 
const ab = true
if (ab === false) {
    // do what you want
    return
} else if (ab === true) {
    x = [1, 2, 3]
}
console.log(x)

or like this:

let x 
const ab = true
if (ab === false) {
    // do what you want
} else if (ab === true) {
    x = [1, 2, 3]
}
if (x != null && x != undefined) {
    console.log(x)
}

  • Related