1. The following function is immediately invoked. function f() { return 1; } True False 2. A function can return another function. True False 3. A variable that is declared outside of a function is called a(n) _______________ variable. global local program class 4. What does the following code display? var a = 1; function f() { function n() { console.log(a); } var a = 2; n(); } f(); undefined 1 NaN 2
1. The following function is immediately invoked.
function f() { return 1; }
True | |
False |
2. A function can return another function.
True | |
False |
3. A variable that is declared outside of a function is called a(n) _______________ variable.
|
global |
|
local |
|
program |
|
class |
var a = 1;
function f() {
function n() {
console.log(a);
}
var a = 2;
n();
}
f();
|
undefined |
|
1 |
|
NaN |
|
2 |
An immediately-invoked function expression immediately calls a function. So the function is executed immediately after the completion of the definition.
For example: (function() { console.log('Welcome to the Internet. Please follow me.'); }());
Answer 1: False. The given function is not immediately invoked.
Assigning a variable to a function copies the reference to the function. By putting the parenthesis at the end of a function name, calls the function, returning the functions return value.
Answer 2: True. Since a function can return another function in Javascript.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images