Consider the following code:
function someFunc() {
let bar = 1;
function zip() {
alert(bar); // 1
let beep = 2;
function foo() {
alert(bar); // 1
alert(beep); // 2
}
}
return zip
}
function sayHello(name) {
const sayAlert = function() {
alert(greeting)
}
const sayZip = function() {
someFunc.zip()
}
let greeting = `Hello ${name}`
return sayAlert
}
- How would you get an alert of 'Hello Bob'?
- sayHello()('Bob')
- sayHello('Bob')()*
- sayHello('Bob')
- someFunc()(sayHello('Bob'))
- What will alert(greeting) do in the preceding code?
- Alert 'greeting'
- Alert 'Hello Alice'
- Throw an error
- None of the above
- How would we get an alert message of 1?
- someFunc()()*
- sayHello().sayZip()
- alert(someFunc.bar)
- sayZip()
- How would we get an alert message of 2?
- someFunc().foo()
- someFunc()().beep
- We can't, because it's not in scope
- We can't, because it's not defined
- How can...