What does it mean to invoke a function?
A
Define the function B
Declare the function parameters C
Execute or call the function D
Return from a function
Analysis & Theory
Invoking a function means calling it so that the code inside it runs.
Which of the following correctly invokes a function named `sayHi`?
A
call sayHi B
sayHi[] C
sayHi() D
invoke sayHi
Analysis & Theory
Functions are invoked using parentheses: `sayHi()`.
What is the output of this code?
```js
function add(a, b) { return a + b; }
console.log(add(2, 3));
```
A
`add` B
undefined C
23 D
5
Analysis & Theory
The function `add` returns 2 + 3, which is 5.
What happens if you invoke a function without parentheses?
A
It runs the function B
It throws an error C
It returns the function object D
It returns undefined
Analysis & Theory
Referencing a function without parentheses returns the function itself.
Which of the following is NOT a valid way to invoke a function?
A
`myFunc()` B
`myObj.myFunc()` C
`(function(){})()` D
`function myFunc()`
Analysis & Theory
`function myFunc()` defines a function, but does not invoke it.
What is a self-invoking function?
A
A function that runs automatically when defined B
A recursive function C
A function with no name D
A function called from another file
Analysis & Theory
Self-invoking (IIFE) functions run immediately after they are defined.
Which of the following is a self-invoking function?
A
`function() {}();` B
`(function() {})();` C
`function() => {};` D
`let f = new Function();`
Analysis & Theory
`(function() {})();` is an Immediately Invoked Function Expression (IIFE).
Which method calls a function with a specified `this` value?
A
apply() B
invoke() C
run() D
execute()
Analysis & Theory
The `apply()` method calls a function with a given `this` value and arguments as an array.
Which function invocation pattern sets the `this` value explicitly?
A
`myFunc()` B
`myFunc.apply(obj)` C
`myFunc.name` D
`myFunc.arguments`
Analysis & Theory
`apply()` sets the `this` context explicitly during invocation.
What will be the value of `this` in a regular function called without context?
A
undefined B
global object (window in browsers) C
null D
the function name
Analysis & Theory
In non-strict mode, `this` in a regular function defaults to the global object when not bound.