Week 2
Quiz 5

Quiz 5: Immediately Invoked Function Expressions (IIFE)

Question 1

Shows true?
JavaScript
let x = 0;
function two() {
    let x = 2;
    return x;
}
two();
try { // is x unchanged?
    document.writeln(x === 0);
} catch (e) {
    document.writeln(false);
}

Question 2

Shows true?
JavaScript
let x = 0;
function two() {
    let x = 2;
    return x;
}();
 
try { // is x unchanged?
    document.writeln(x === 0);
} catch (e) {
    document.writeln(false);
}

Question 3

Shows true?
JavaScript
let x = 0;
(function two() {
    let x = 2;
    return x;
})();
 
try { // is x unchanged?
    document.writeln(x === 0);
} catch (e) {
    document.writeln(false);
}

Question 4

Shows true?
JavaScript
let x = 0;
(function() {
    let x = 2;
    return x;
})();
 
try { // is x unchanged?
    document.writeln(x === 0);
} catch (e) {
    document.writeln(false);
}

Question 5

Shows true?
JavaScript
let x = 0;
( () => {
    let x = 2;
    return x;
})();
 
try { // is x unchanged?
    document.writeln(x === 0);
} catch (e) {
    document.writeln(false);
}

Question 6

Shows true?
JavaScript
x = 0;
( () => {
    x = 2;
    return x;
})();
 
try { // is x unchanged?
    document.writeln(x === 0);
} catch (e) {
    document.writeln(false);
}