dart: Operator [??=, ??]

Darcy Daeseok YU ·2022년 12월 2일
0

Operator : ??
If Left side is null then show right side
null ?? 'shown' or non-null ?? 'not Shown'

String capitalizeName(String? name, [int? age = 10, String? cntry = 'kor']) {
  if (name != null) {
    return name.toUpperCase();
  }

return 'Name is null';
}

String capitalizeName1(String? name, [int? age = 10, String? cntry = 'kor']) {
return name != null ? name.toUpperCase() : 'Name is null';
}

String capitalizeName2(String? name, [int? age = 10, String? cntry = 'kor']) {
return name?.toUpperCase() ?? 'Name is null';
}


> Opeator : ??= 
var? name;

// do something and 


name ??= 'new Name' // 값이 비어있으면 해당 값을 입력해라.
profile
React, React-Native https://darcyu83.netlify.app/

0개의 댓글