1
function b() {
   return "B";
}
function output(par){
    var l=par;
    alert(l);
}
output(b);

The result i get is:

function b() (
     return "B";
)

But when i define the variable "l" outside the function. Like:

function b() {
   return "B";
}
var l=b();
alert(l);
}

The result is "B";

How do i make the function behave like in the second case but inside the function, and why is not treating it in the same way?

2 Answers 2

3

When you do this:

var l = b();

...you are calling b, and assigning the result to l. If you wanted l to refer to the function object b, you would just say:

var l = b;

(Likewise, in your output() function, if you did var l = par(), it would display "B".)

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

1 Comment

Perhaps what he's looking for is output(b());
1

In the first case: you send function b as a parameter into function output . In the second case: you call the funcation b using "b()",so at this time the varaible l is B other than the function itself.

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.