Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is `== null` preferable to `is Null`?

Tags:

dart

In Dart, checking for a value to be == null seems similar to checking if it is Null. Why is the former more preferable?

like image 392
Ganymede Avatar asked Feb 18 '14 22:02

Ganymede


2 Answers

It is the type of comparison you are doing. In == null, you are comparing an object/primative to null whereas in the latter, is Null, null is an object. It makes no difference in the compiler.

== null is more favourable as the two being compared could be both primitives, which saves memory in the system.

like image 175
ylun.ca Avatar answered Sep 19 '22 19:09

ylun.ca


== null is familiar to developers coming from other popular languages.

like image 26
Greg Lowe Avatar answered Sep 21 '22 19:09

Greg Lowe