Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference between if( null == this.somevariable ) and if( this.somevariable == null)

Dumb question I get it..but what the difference between these two statements

if( null == this.someVariable)
{
 //do something
}

and 

if( this.someVariable == null )
{
//do something.
}
like image 978
Waddaulookingat Avatar asked Mar 03 '26 09:03

Waddaulookingat


2 Answers

They are the same from a code point of view. Some people prefer the first style, because if you then make a mistake and type = instead of == you'll get an error

like image 57
MicroVirus Avatar answered Mar 05 '26 22:03

MicroVirus


There's absolutely no difference at all. Except maybe which looks better to you.

It's a relic from the C\C++ world where:

if(null = someVariable)
{
}

Would give an error. But:

if(someVariable = null)
{
}

Would not.

like image 25
i3arnon Avatar answered Mar 05 '26 21:03

i3arnon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!