-3

I have two different JavaScript functions in same file, like this:

function functionOne(a)
{
   if(a)
   {
       return true;
   }
   else
   {
       return false;
   }
}

function functionTwo(b)
{
   //I want to access if condition parameter a here
}

I want to access functionOne if condition parameter a in functionTwo.

5
  • 3
    functionTwo(functionOne(a)) will pass the returned value of functionOne as functionTwo's parameter. Commented May 31, 2013 at 7:07
  • i don't think it works... the parameter passed to functioneOne() is local to that function... it is better to declare a common vairable and check accordingly... Commented May 31, 2013 at 7:08
  • I hope this answer will help you Commented May 31, 2013 at 7:10
  • so i put it like as function functionTwo(b) { functionTwo(functionOne(a)) } Commented May 31, 2013 at 7:10
  • You can call function functionOne two time with different parameter like functionOne(a),functionOne(b). Why write another function ? Commented May 31, 2013 at 7:12

2 Answers 2

0
function functionTwo(b)
{

    if(functionOne(b))
        return true;
    else
        return false;

}
Sign up to request clarification or add additional context in comments.

Comments

0

The following are the two ways....

Option 1:

<script>
var newVar = "";
function functionOne(a)
{

if(a) { newVar = true; return true; } else { return false; } }

function functionTwo(b)
{
 //user newVar vairalbe to get the value
 //i want to access if condition parameter a here
}

Option 2:

<script>
function functionOne(a)
{
if(a)
{
    return a;
}
else
{
    return false;
}
}
function functionTwo(b)
{
//   call functionOne(a) to get the value;
//i want to access if condition parameter a here
}
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.