Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if ((x = SomeObj.MethodThatReturnsALong(42)) != null) 1

Status
Not open for further replies.

JustinEzequiel

Programmer
Jul 30, 2001
1,192
PH
Greetings,

I know some JavaScript but this has me stumped.
I am translating some vendor-supplied code to another programming language and I do not know how an assignment statement can or cannot return a null.
I.e., is the snippet below checking if x is not null?
If not, then what is the condition checking?

Code:
var x;
if ((x = SomeObj.MethodThatReturnsALong(42)) != null)
    {
    // more code here
    }

Thanks
 
It's an assignment and a check in one go. It could be written as:

Code:
var x = SomeObj.MethodThatReturnsALong(42);
if (x != null) {
	// more code here
}

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thanks Dan.
Had scanned w3schools' JavaScript references for this and did not find any mention that one could do this.
I was concerned that my "translation" may not accurately reflect the original.
Thanks again.
 
Hi

JustinEzequiel said:
I know some JavaScript but this has me stumped.
Just as a note, that is not JavaScript specific. That works in most of the languages with C-like syntax. It is just matter of operator precedence. I do not think you will find that explicitly mentioned in any language reference.

Feherke.
 
Just as a note, that is not JavaScript specific. That works in most of the languages with C-like syntax. It is just matter of operator precedence.
Thanks. I will try to remember that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top