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

What is Fat Arrow Notation in Dart and when do you use it?

Câu trả lời

The fat arrow notation (=>) in Dart is a shorthand syntax for defining single-expression functions. It allows you to write concise function expressions in a single line of code[1].

The syntax for using the fat arrow notation is:

dart Copy
ReturnType functionName(parameters) => expression;

Here's how it works:

  • The ReturnType specifies the return type of the function, such as void, int, bool, etc.
  • functionName is the name of the function.
  • parameters represents the parameters the function requires, if any.
  • expression is the single expression to be evaluated and returned by the function.

The fat arrow notation is particularly useful when you have a function that performs a simple operation and returns a value in a single line of code. For example:

dart Copy
bool isEven(int number) => number % 2 == 0;

In this case, the isEven function checks if a given number is even and returns a boolean value.

You should use the fat arrow notation when:

  1. **The function body consists...
junior

junior

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

middle

How to declare async function as a variable in Dart?

middle

What is profile mode and when do you use it?

middle

Name some cons of using Flutter?

Bình luận

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

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