Dart Memo : ?? operator

Dr_Skele·2023년 1월 3일
0

Dart

목록 보기
3/5

When checking for null, we frequently use a ternary operator. But there is an operator that could make code a bit shorter.

void main() {
  int getLength(List? list) => list?.length ?? 0; // list != null ? list.length : 0

  print(getLength(null));
}

'??' operator will give the value on the left if the value isn't null. Otherwise, returns the value on the right.

profile
Tireless And Restless Debugging In Source : TARDIS

0개의 댓글