Difference between conventions

Just wanted to know if anyone could explain the difference between these two conventions:

if ( !object ) 

if ( object == null )

where object is an instance of a user-defined class.

I'm sure these two cannot be used interchangeably, or are they?

Thank.

+3
source share
3 answers

The effect is the same in practice, so I think you could say that they are interchangeable.

In a boolean context (for example, conditional), the expression evaluates to both true and false.

In ActionScript 3.0, the following values ​​are evaluated as false:

  • Lying
  • Null
  • 0
  • NaN
  • "" (empty line)
  • undefined
  • invalid

Everything else evaluates to true.

A reference to a custom instance of a class can be either null or not null.

So in this case:

if ( object == null )

, , null.

:

if ( !object )

object false, object - null. null, . , , . , , object null, . , , object null, .

, ; ; , false , null; , , null, null. .

+7

- . , not (!) true, , false, .

, null .

, , , 0, false, null ( "\ 0" ) .

ActionScript, false, null, 0 .. .

+1

, :) , , ; - true, .

"!" " " "==" , ,

0

Source: https://habr.com/ru/post/1773896/


All Articles