1

Hi I am new to javascript. I am looking at big javascript code already working fine. It contains following statements :

function(a){
  return this.prt = a,this;
}

and in the client code, they are using it as

obj.a(34).a(54)

I want to know what's happening here ? Does javascript allows returning of multiple values.

Pardoning for may be such a silly question. I have googled out, but couldn't find any good references.

Thanks in advance.

2 Answers 2

2

I tried running these lines of code on console.

this.name = "yasser";
function demo(){
    return this.name = "neel", 10;
}

And here is what I got,

this.name evaluates to 'neel' and demo() fn returns 10.

So no you cannot return multiple values from javascript. You can return multiple values combining them into one object.

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

Comments

0

I looked at this post How does this return statement with multiple values (variables) works?. However, it's for c language, but I think the rule for comma operator applier here also. Thus, return a,b will result into evaluation of a and then b and returning result of b's evaluation.

1 Comment

That's correct. In your example, it's evaluating this.prt = a (i.e. assigning the value of a to this.prt), then it's evaluating this, and the result of the entire expression is the last thing evaluated, this, which is then returned.

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.