How do you create an Immediately Invoked Function Expression (IIFE)?
A). (function() { alert('IIFE'); })();
B). function() { alert('IIFE'); }();
C). (function { alert('IIFE'); })();
D). function() { alert('IIFE'); };
What will be the output of the following code? var double = function(x) { return x * 2; }; console.log(double(5));
A). 10
B). 5
C). undefined
D). double
What will be the output of the following code? var sayHi = function() { return 'Hi'; }; console.log(sayHi());
A). Hi
B). undefined
C). sayHi
D). function
How can you store a function as a property of an object?
A). var obj = { method: function() { alert('Hello'); } };
B). var obj = { method: alert('Hello'); };
C). var obj = { method: function { alert('Hello'); } };
D). var obj = { function() { alert('Hello'); } };
Which of the following correctly demonstrates a function returning another function?
A). function outer() { return function() { alert('Inner'); }; }
B). function outer() { function() { alert('Inner'); } return; }
C). function outer() { function() { alert('Inner'); }; }
D). function outer() { return function { alert('Inner'); }; }
Which of the following is an example of using a function as a return value?
A). function outer() { return function() { alert('Inner'); }; }
B). function outer() { function() { alert('Inner'); }; return; }
C). function outer() { function() { alert('Inner'); }; }
D). function outer() { return function { alert('Inner'); }; }
What will be the output of the following code? var counter = (function() { var count = 0; return function() { return ++count; }; })(); console.log(counter()); console.log(counter());
A). 1, 2
B). 0, 1
C). undefined, undefined
D). 2, 4
Which of the following is an example of an arrow function assigned to a variable?
A). var add = (a, b) => { return a + b; };
B). var add = (a, b) => return a + b;
C). var add = (a, b) => { a + b };
D). var add = (a, b) { return a + b; };
What will be the output of the following code? var add = new Function('a', 'b', 'return a + b'); console.log(add(2, 3));
A). 5
B). add
C). undefined
D). 2 3
Which of the following is true about functions in JavaScript?
A). Functions can be assigned to variables
B). Functions can be passed as arguments to other functions
C). Functions can be returned from other functions
D). All of the above