Week 8
Quiz 18

Quiz 18: Callback functions used well and badly

Question 1

Shows true?
JavaScript
function handle(callback) {
    const result = [];
    callback(result);
    return result;
}
 
let it = [];
handle(it => it.push(1)).length === 1

Question 2

Shows true?
JavaScript
function handle(callback) {
    const result = [];
    callback(result);
    return result;
}
 
handle(() => it.push(1)).length === 1

Question 3

Shows true?
JavaScript
function handle(callback) {
    const result = [];
    callback(result);
    return result;
}
 
handle(it.push(1)).length === 1

Question 4

Shows true?
JavaScript
function handle(callback) {
    const result = [];
    callback([]);
    return result;
}
 
handle(it => it.push(1)).length === 1

Question 5

Shows true?
JavaScript
function handle(callback) {
    const result = [];
    return callback(result);
}
 
handle(() => [1]).length === 1

Question 6

Shows true?
JavaScript
function handle(callback) {
    const result = [];
    callback(result);
    return result;
}
 
handle(it => it.push(1)).length === 1

Question 7

Shows true?
JavaScript
function handle(callback) {
    return callback([]);
}
 
handle(it => {
    it.push(1);
    return it;
}).length === 1

Question 8

Shows true?
JavaScript
function handle(callback) {
    const result = [];
    callback(result);
    return result;
}
 
let it = [];
handle(it.push(1)).length === 1

Question 9

Shows true?
JavaScript
function handle(callback) {
    const result = [];
    callback(result);
    callback(result);
    return result;
}
 
handle(it => it.push(1)).length === 2

Question 10

Shows true?
JavaScript
function handle(callback) {
    const result = [];
    callback(result);
    return result;
}
 
let it = [];
handle(() => it.push(1)).length === 1

Question 11

Shows true?
JavaScript
function handle(callback) {
    const result = [];
    callback(result);
    return result;
}
 
handle(() => [1]).length === 1

Question 12

Shows true?
JavaScript
function handle(count, callback) {
    const result = [];
    for (let i = 0; i < count; i++) {
        callback(result);
    }
    return result;
}
 
handle(3, it => it.push(1)).length === 3