[{"id":"dartbeginner-001","courseId":"dart-beginner","domain":"variables-and-operators","topic":"var and type inference","prompt":"A teammate writes the line below and asks what type Dart gives the variable name. Which answer is correct?","hint":"Think about what the var keyword takes its type from.","explain":"A declaration can leave out the type, and the compiler still assigns one. Writing the type out is optional, and it makes the intent explicit.","source":"https://dart.dev/language/variables","interaction":{"type":"single"},"options":[{"id":"a","text":"String, inferred from the value 'Bob'","why":"The starting value is a String, so Dart infers the variable's type as String."},{"id":"b","text":"dynamic, so any value can be stored later","whyNot":"dynamic is a type you ask for explicitly; var doesn't choose it for you."},{"id":"c","text":"Object, because var accepts any type","whyNot":"Object is a type you write when a variable shouldn't be limited to one type; var doesn't pick it."},{"id":"d","text":"No type at all, until you annotate it","whyNot":"var still gives the variable a type, inferred from the value on the right."}],"answer":"a","explanation":"var infers a variable's type from its initial value: in var name = 'Bob', the type of name is inferred to be String, and you can also write the type out explicitly.","concept":"var infers a variable's type from its initial value: in var name = 'Bob', the type of name is inferred to be String, and you can also write the type out explicitly.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"var name = 'Bob';","takeaways":["var takes its type from the first value; write a type yourself to be explicit."]},{"id":"dartbeginner-002","courseId":"dart-beginner","domain":"variables-and-operators","topic":"final and const","prompt":"A program reads a user's name at run time and stores it in a variable that must not change afterward. Which keyword fits?","hint":"Compare what each keyword requires of the value it stores.","explain":"Dart has more than one way to promise that a value won't change, and the promises differ in when the value must be available. Think about whether it must be known before the program runs, or only while it runs.","source":"https://dart.dev/language/variables","interaction":{"type":"single"},"options":[{"id":"a","text":"final","why":"A final variable can be set only once, and its value can come from code that runs at run time."},{"id":"b","text":"const","whyNot":"A const variable must be a compile-time constant, so it can't hold a value read at run time."},{"id":"c","text":"var","whyNot":"var allows reassignment, so the value could change later."},{"id":"d","text":"static","whyNot":"static gives class-level storage; it doesn't stop the variable from being assigned again."}],"answer":"a","explanation":"A final variable can be set only once and may get its value at run time; a const variable is a compile-time constant.","concept":"A final variable can be set only once and may get its value at run time; a const variable is a compile-time constant.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Use final for a value set once at run time; use const only for values fixed at compile time."]},{"id":"dartbeginner-003","courseId":"dart-beginner","domain":"variables-and-operators","topic":"Default value of nullable variables","prompt":"Inside a function, this declaration gives lineCount the number 0 until something assigns it.","hint":"Think about the starting state of a nullable variable, before any assignment.","explain":"A variable declared without a value still starts in some state, and that state depends on whether its type allows null. Dart treats every value as an object, so the same rule applies across the board.","source":"https://dart.dev/language/variables","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Many languages start numbers at zero, but a nullable Dart variable starts as null, not 0."},{"id":"b","text":"False","why":"Uninitialized nullable variables start as null, and numeric types are included."}],"answer":"b","explanation":"Uninitialized variables with a nullable type start as null, even numeric ones, because numbers are objects in Dart.","concept":"Uninitialized variables with a nullable type start as null, even numeric ones, because numbers are objects in Dart.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"int? lineCount;","takeaways":["Nullable variables start as null, numbers included; never assume a starting value of zero."]},{"id":"dartbeginner-004","courseId":"dart-beginner","domain":"variables-and-operators","topic":"Integer division with ~/","prompt":"A script divides seven by two with the integer-result operator, as in the code below. What does it print?","hint":"Compare the integer-result operator with the ordinary slash.","explain":"Division can give a whole-number answer or a fractional one, and a language may offer a separate operator for each kind. Think about which type of value each operator is meant to produce.","source":"https://dart.dev/language/operators","interaction":{"type":"single"},"options":[{"id":"a","text":"3","why":"The operator divides and returns an integer, so the fractional part is dropped and the answer is 3."},{"id":"b","text":"3.5","whyNot":"That is the result of the ordinary slash operator, which returns a double."},{"id":"c","text":"4","whyNot":"The integer-result operator drops the remainder; it does not round up."},{"id":"d","text":"3.0","whyNot":"The result is an int, so no decimal point is printed."}],"answer":"a","explanation":"~/ divides and returns an integer result, so 5 ~/ 2 == 2; the ordinary slash returns a double instead.","concept":"~/ divides and returns an integer result, so 5 ~/ 2 == 2; the ordinary slash returns a double instead.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"print(7 ~/ 2);","takeaways":["~/ returns an int and drops the remainder; / returns a double."]},{"id":"dartbeginner-005","courseId":"dart-beginner","domain":"variables-and-operators","topic":"Conditional expression","prompt":"A developer writes the code below. Which TWO statements about the conditional operator are correct?","hint":"Think about which branch runs and what the whole expression produces.","explain":"Dart can choose between two results inside one expression, which avoids a full if statement. Think about which parts of such an expression run, and what kind of thing the whole expression is.","source":"https://dart.dev/language/operators","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"It evaluates only the branch the condition picks, and returns that branch's value.","why":"If the condition holds, the first expression is evaluated; otherwise the second is, and its value is returned."},{"id":"b","text":"It produces a value, so it can initialize a variable in one line.","why":"The result can be assigned directly, which is why it suits choosing a value from a boolean."},{"id":"c","text":"It evaluates both branches first, then keeps the one that matches.","whyNot":"The branch that isn't picked never runs, so any side effects in it never happen."},{"id":"d","text":"A non-zero number counts as true in the condition, as in C.","whyNot":"Dart requires a bool in a condition; numbers are not accepted in its place."},{"id":"e","text":"It works only when the condition is null, so it matches ??.","whyNot":"?? is a separate operator that checks for null; the conditional operator tests a boolean."},{"id":"f","text":"Both branches must be text, so it fits only string values.","whyNot":"The two branches can be expressions of any type; in this example they happen to be strings."}],"answer":"ab","explanation":"The conditional operator evaluates only the expression that the condition selects, and the whole expression returns that value.","concept":"The conditional operator evaluates only the expression that the condition selects, and the whole expression returns that value.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"var visibility = isPublic\n    ? 'public'\n    : 'private';","takeaways":["A conditional expression runs only the branch its condition picks, and returns that value."]}]