Quiz 27: Data Flow Variables
💡
All questions in this quiz use the following definition of a DataFlowVariable:
DataFlowVariable
const DataFlowVariable = createValue => {
let value = undefined;
return () => {
if (value !== undefined) {
return value
}
value = createValue();
return value;
}
};Question 1
Shows
'2'?JavaScript
const x = DataFlowVariable(() => y() * 2);
let y = DataFlowVariable(() => 1);
y = DataFlowVariable(() => 2);
document.writeln(x());Question 2
Shows
'2'?JavaScript
const x = DataFlowVariable(() => y() * 2);
let y = DataFlowVariable(() => 1);
document.writeln(x());Question 3
Shows
'4'?JavaScript
const x = DataFlowVariable(() => y() * 2);
let y = DataFlowVariable(() => 1);
y = DataFlowVariable(() => 2);
document.writeln(x());Question 4
Shows
'2'?JavaScript
const x = DataFlowVariable(() => y() * 2);
let y = DataFlowVariable(() => 1);
x();
y = DataFlowVariable(() => 2);
document.writeln(x());Question 5
Shows
'4'?JavaScript
const x = DataFlowVariable(() => y() * 2);
let y = DataFlowVariable(() => 1);
x();
y = DataFlowVariable(() => 2);
document.writeln(x());