Answers Latest Version Already Passed
What is a function in JavaScript?
✔✔ A function is a reusable block of code that performs a specific task when called.
How do you define a function in JavaScript?
✔✔ Using the `function` keyword followed by the function name and parentheses, like this:
`function myFunction() {}`.
How do you call a function in JavaScript?
✔✔ By writing its name followed by parentheses, like this: `myFunction();`.
What is the difference between a function declaration and a function expression?
✔✔ A function declaration is hoisted and can be used before its definition, while a function
expression is assigned to a variable and cannot be used before it is defined.
Can a JavaScript function return a value?
✔✔ Yes, by using the `return` statement inside the function.
1
,What happens if a function does not have a `return` statement?
✔✔ It returns `undefined` by default.
How do you pass arguments to a function?
✔✔ By placing values inside the parentheses when calling the function, like this: `myFunction(5,
10);`.
What is an anonymous function?
✔✔ A function without a name, often assigned to a variable or used as a callback.
What is an arrow function in JavaScript?
✔✔ A shorter syntax for writing functions using `=>`, like this: `const add = (a, b) => a + b;`.
How do you create a function that takes a variable number of arguments?
✔✔ By using the rest parameter syntax, like this: `function myFunction(...args) {}`.
What is the purpose of the `arguments` object inside a function?
2
, ✔✔ It holds all the arguments passed to the function, allowing access even if parameters are not
explicitly defined.
Can a function be assigned to a variable?
✔✔ Yes, functions are first-class objects and can be stored in variables.
What is a higher-order function?
✔✔ A function that takes another function as an argument or returns a function.
How do you create a function inside another function?
✔✔ By defining a function within the body of another function.
What does `this` refer to inside a function?
✔✔ It depends on how the function is called; in a method, it refers to the object, while in a
regular function, it refers to `window` (or `undefined` in strict mode).
What is a callback function?
✔✔ A function passed as an argument to another function to be executed later.
3