Câu hỏi phỏng vấn Flutter
Câu hỏi

What are Null-aware operators?

Câu trả lời

Null-aware operators in Dart are a set of operators that allow you to safely handle null values in your code. They help you avoid runtime errors caused by null values and make your code more concise and readable. Here are the main null-aware operators in Dart:

  1. The null-coalescing operator (??): This operator returns the value on its left side if it's not null, otherwise it returns the value on its right side. It's useful for providing a default value when a variable might be null[1][2][3].

Example:

dart Copy
String? username;
String defaultUsername = username ?? 'Guest';
  1. The null-aware assignment operator (??=): This operator assigns a value to a variable only if the variable is currently null. If the variable is not null, it remains unchanged[2][3].

Example:

dart Copy
String? username;
username ??= 'Guest';
  1. The null-aware access operator (?.): This operator allows you to safely access properties and methods of an object that might be null. If the object is null, it returns null i...
middle

middle

Gợi ý câu hỏi phỏng vấn

expert

How is AnimationController different from Timer ?

middle

How is whenCompleted() different from then() in Futurs?

expert

List some approaches for State Management in Flutter

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào