How can you pass a function as an argument to another function?
A). performAction(function() { alert('Action!'); });
B). performAction(function { alert('Action!'); });
C). performAction(function() alert('Action!'););
D). performAction(function() alert('Action!'))
How do you define a function using a function expression?
A). var myFunc = function() { alert('Hello'); };
B). function myFunc() { alert('Hello'); }
C). var myFunc = function { alert('Hello'); };
D). var myFunc() { alert('Hello'); }
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
How do you define an anonymous function assigned to a variable?
A). var anon = function() { alert('Anonymous!'); };
B). var anon = function { alert('Anonymous!'); };
C). function anon() { alert('Anonymous!'); }
D). var anon = function anonymous() { alert('Anonymous!'); };
How can you define a method inside an object?
A). var obj = { method: function() { alert('Hello'); } };
B). var obj = { method() { alert('Hello'); } };
C). Both A and B
D). var obj = { function method() { alert('Hello'); } };
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
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; };
How can you invoke a function stored in a variable doSomething?
A). doSomething();
B). call doSomething;
C). doSomething[];
D). invoke(doSomething);
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'); } };
What is the term for a function that is passed as an argument to another function?
A). Callback function
B). Nested function
C). Helper function
D). Inner function