Week 2
Quiz 4

Quiz 4: Scoping

Question 1

Shows true?
JavaScript
function two() {
    let x = 2;
    return x;

try { // is x in scope?
    x;
    document.writeln(true);
} catch (e) {
    document.writeln(false);
}

Question 2

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

Question 3

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

Question 4

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

Question 5

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