[{"id":"javascriptintermediate-001","courseId":"javascript-intermediate","domain":"values-and-types","topic":"typeof null","prompt":"A helper runs typeof value === 'object' before it reads value.name. Which value passes that check even though it is not an object?","hint":"Consider which value was meant to stand for 'no object at all'.","explain":"typeof returns one string per kind of value, but its results are not always a perfect map of the language's ideas. Some results come from early design choices, so a typeof check alone can mislead.","source":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof","interaction":{"type":"single"},"options":[{"id":"a","text":"null","why":"typeof null returns 'object' because of an early implementation detail, so this check passes for null."},{"id":"b","text":"undefined","whyNot":"typeof undefined returns 'undefined', so it fails the check."},{"id":"c","text":"A function","whyNot":"typeof on a function returns 'function', not 'object'."},{"id":"d","text":"NaN","whyNot":"NaN is a number, so typeof NaN returns 'number'."}],"answer":"a","explanation":"typeof null === 'object' is a long-standing artifact of the first JavaScript implementation; a proposed fix was rejected, so it remains.","concept":"typeof null === 'object' is a long-standing artifact of the first JavaScript implementation; a proposed fix was rejected, so it remains.","rev":1,"kind":"scenario","takeaways":["typeof null is 'object', so check for null explicitly before reading properties."]},{"id":"javascriptintermediate-002","courseId":"javascript-intermediate","domain":"values-and-types","topic":"Loose equality coercion","prompt":"Put these checks of the == (loose equality) algorithm in the order the engine applies them.","hint":"Think about which operand types need conversion before comparing, and which cannot be converted.","explain":"== decides some pairs at once and converts the rest in stages. A conversion happens only when the earlier checks have not already decided the answer.","source":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality","interaction":{"type":"sort","items":[{"text":"Same type: compare the two values directly","why":"Operands of one type need no conversion, so they are compared right away."},{"text":"One side null or undefined: the other must also be null or undefined","why":"This settles the answer before any object or Boolean conversion happens."},{"text":"Object against a primitive: convert the object to a primitive","why":"Only after this conversion can the values be compared with the primitive rules."},{"text":"Symbol against a non-Symbol: return false","why":"A Symbol cannot be converted, so the comparison ends as false."},{"text":"Boolean against a non-Boolean: convert the Boolean to a number","why":"true becomes 1 and false becomes 0, and then the comparison runs again."}]},"options":[],"answer":"o:abcde","explanation":"Loose equality checks in fixed stages: same type, then null and undefined, then object to primitive, then Symbol, then Boolean to number.","concept":"Loose equality checks in fixed stages: same type, then null and undefined, then object to primitive, then Symbol, then Boolean to number.","rev":1,"kind":"scenario","takeaways":["== converts operands only in stages, so its results follow fixed rules rather than guesses."]},{"id":"javascriptintermediate-003","courseId":"javascript-intermediate","domain":"values-and-types","topic":"Number.isNaN versus isNaN","prompt":"A form validator uses the global isNaN(). Which call returns true from isNaN() but false from Number.isNaN()?","hint":"Ask which of the two checks converts its argument to a number first.","explain":"Two built-in checks both test for NaN, but they handle non-number inputs differently. One of them converts its argument to a number first, which changes the result for strings and other values.","source":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN","interaction":{"type":"single"},"options":[{"id":"a","text":"isNaN('blabla')","why":"The global isNaN converts the string to a number, gets NaN, and returns true."},{"id":"b","text":"Number.isNaN('blabla')","whyNot":"Number.isNaN never converts its argument, so a string is not the number NaN and it returns false."},{"id":"c","text":"isNaN(true)","whyNot":"The global version converts true to 1, which is not NaN, so it returns false."},{"id":"d","text":"Number.isNaN(0 / 0)","whyNot":"0 / 0 is the number NaN, so both checks return true here."}],"answer":"a","explanation":"Global isNaN() coerces its argument to a number before testing; Number.isNaN() returns true only for a value that is the number NaN.","concept":"Global isNaN() coerces its argument to a number before testing; Number.isNaN() returns true only for a value that is the number NaN.","rev":1,"kind":"scenario","takeaways":["Use Number.isNaN() to avoid false positives from strings, booleans, and undefined."]},{"id":"javascriptintermediate-004","courseId":"javascript-intermediate","domain":"values-and-types","topic":"Logical OR results","prompt":"In JavaScript, the expression true || false && false evaluates to false, because || is applied before &&.","hint":"Check which operator groups its operands first when no parentheses are used.","explain":"When operators appear without parentheses, the language groups them by a fixed priority. Parentheses override that grouping, so the order in which operators apply matters.","source":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Applying || first would give false, but && binds tighter, so the statement does not hold."},{"id":"b","text":"False","why":"&& binds tighter, so false && false is evaluated first; true || false then gives true, not false."}],"answer":"b","explanation":"&& has higher precedence than ||, so a || b && c is grouped as a || (b && c).","concept":"&& has higher precedence than ||, so a || b && c is grouped as a || (b && c).","rev":1,"kind":"scenario","takeaways":["Mixed && and || without parentheses follow precedence, so add parentheses when the intent matters."]},{"id":"javascriptintermediate-005","courseId":"javascript-intermediate","domain":"values-and-types","topic":"Logical AND short-circuit","prompt":"The code runs in a browser. What is printed, in order, when the script runs?","hint":"A && stops as soon as one operand is falsy.","explain":"&& evaluates its operands from left to right and can stop early. Whether the later operand runs depends on the value of the earlier one, and the result is the value that decided it.","source":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND","interaction":{"type":"single"},"options":[{"id":"a","text":"'checking', then false","why":"isAdmin() returns false, so && stops there and gives that false; deleteAll never runs."},{"id":"b","text":"'checking', 'deleting', then false","whyNot":"deleteAll would run only if the left operand were truthy, so this ignores the short-circuit."},{"id":"c","text":"'checking', 'deleting', then true","whyNot":"Both functions would have to run, and && would have to return true, which it does not do here."},{"id":"d","text":"'deleting', then false","whyNot":"The left operand is always evaluated first, so 'deleting' cannot print before 'checking'."}],"answer":"a","explanation":"&& stops at the first falsy operand and returns that operand's value without evaluating the rest.","concept":"&& stops at the first falsy operand and returns that operand's value without evaluating the rest.","rev":1,"kind":"scenario","code":"function isAdmin() {\n  console.log('checking');\n  return false;\n}\nfunction deleteAll() {\n  console.log('deleting');\n  return true;\n}\nconst ok = isAdmin() && deleteAll();\nconsole.log(ok);","takeaways":["The right side of && runs only when the left side is truthy."]}]