0

If I have:

function Function1(){
    var Value = true;

    return Value;

};

How can I use the returned value "Value" in another function for it to be used as true, if I use it as below, it doesn't returns nothing.

function Function2(){
    if(Function1 == true){
        console.log("Hello")
    }
}
Mike Alvarado
  • 109
  • 10

4 Answers4

0
function Function2(){
    if(Function1() == true){
        console.log("Hello")
    }
}

only replace Function2 with Function2()

Bijender Singh Shekhawat
  • 3,934
  • 2
  • 30
  • 36
0

In order to get the returned value you need to call the function first. What you're doing is evaluating the function itself, not the returned value.

You also don't need the == true part because it will evaluate the returned value anyway.

Change your code to:

function Function2(){
    if(Function1()){
        console.log("Hello")
    }
}
Botimoo
  • 599
  • 6
  • 16
0

Function2 needs to be like this:

function Function2(){
    if(Function1()){
        console.log("Hello");
    }
}

It is because you are calling a function and not a variable. So since you are calling Function1 you need to make sure that you are calling it like this Function1().

If you are calling a variable you can just use the name.

And also since it is a variable of type boolean you can simply use if(Function1()) and omit the == true.

And you call it like this:

var k = Function1();
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
-1

Maybe you have to type brackets '()' after the function:

function Function2(){
    if(Function1() == true){
        console.log("Hello")
    }
}

Because now Syntax Parser thinks that Function1 is a variable.

S.Raman
  • 115
  • 3
  • 12