Dart Syntax Flashcards

(14 cards)

1
Q

How do you fix it by changing only one keyword?

final discountPercentage = 0;
discountPercentage = 20;
final item = ""Google Chromecast"";
final String offer = ""Sale - Up to $discountPercentage% discount on $item! Hurry up!"";
print(offer);
A

Change the final discountPercentage = 0 to var discountPercentage = 0

final can’t be reassigned to another value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the output of the following Dart code snippet?

void main() {
   final val1 = "25";
   final val2 = "50";
   print(val1 + val2);
}
A

2550

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which code snippet correctly calculates and embeds the sum of baseSalary and bonusAmount within a string?

A

print("Total : ${baseSalary + bonusAmount}");

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the result of attempting to compile and run this code?

void main() {
   final item = "Google Chromecast";
   item = "Google Nest Hub";
   print(item);
}
A

The program fails to compile due to error

The final keyword indicates that the variable value cannot be changed after initialization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Create named parameter of v1 and v2 inside method add()

A
int add({int v1, int v2}){
   return v1 + v2;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

According to Dart’s rules, what is the default behavior of positional parameters in a function?

A

They are required, typed in order and must be provided when the function is called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the best practices of Dart naming convention?

A

lowerCamelCase

inputWeight,calCalories

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A function is needed to compare screen time: bool didSpendMoreTime(int timeToday, int timeYesterday). What should the body of this function be to return true only if more time was spent today?

A

return TimeToday > timeYesterday;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is
1. Parameters
2. Arguments

A
  1. Parameters are names listed in the function definition
  2. Arguments are the value passed to a function when it is called
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which function is the starting entry point for Dart & Flutter?

A

void main(){}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to call function
void sendNotification({String message, String recipient})

A

sendNotification(message: "Hello", recipient: "user@gmail.com")

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the key difference between positional and named arguments regarding their default optionality?

A

Positional arguments are required by default, while named arguments are optional by default

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

You have two string variables: final adults = "20"; and final kids = "30";. How would you correctly calculate their sum to get the integer 50?

A

final total=int.parse(adult) + int.parse(kids)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly