Questions
What is the purpose of a function in JavaScript?
- To group related code together
- To reuse code in different parts of a program
- To pass data between different parts of a program
- All of the above
How do you define a function in JavaScript?
- function functionName() {}
- functionName() {}
- var functionName = function() {}
- var functionName = {}
How do you call a function in JavaScript?
- functionName();
- functionName
- functionName = ();
- functionName {}
What is the difference between a function declaration and a function expression?
- Function declarations are hoisted, while function expressions are not.
- Function expressions can be used as values, while function declarations cannot.
- Function declarations can be named, while function expressions cannot.
- All of the above
What is the this keyword in JavaScript?
- It refers to the current object
- It refers to the global object
- It refers to the function that is being called
- It refers to the parent object
What is the difference between arguments and parameters in JavaScript?
- Arguments are the values passed to a function when it is called, while parameters are the variables that are declared in the function definition.
- Parameters are the values passed to a function when it is called, while arguments are the variables that are declared in the function definition.
- Arguments and parameters are the same thing.
- None of the above
What is a callback function?
- A function that is passed as an argument to another function
- A function that is called from within another function
- A function that is defined inside another function
- All of the above
What is the difference between a synchronous function and an asynchronous function?
- Synchronous functions execute immediately, while asynchronous functions execute after some time.
- Asynchronous functions execute immediately, while synchronous functions execute after some time.
- Synchronous functions can be paused and resumed, while asynchronous functions cannot.
- Asynchronous functions can be paused and resumed, while synchronous functions cannot.
What is a higher-order function?
- A function that takes another function as an argument
- A function that returns another function
- A function that can be called multiple times
- All of the above
What is the bind() method in JavaScript?
- It creates a new function that, when called, has its
thiskeyword set to the provided value. - It creates a new function that, when called, has its arguments pre-filled with the provided values.
- It creates a new function that, when called, has its return value set to the provided value.
- None of the above
What is the apply() method in JavaScript?
- It calls a function with a given
thisvalue and arguments provided as an array. - It calls a function with a given
thisvalue and arguments provided as individual parameters. - It calls a function with a given
thisvalue and no arguments. - None of the above
What is the call() method in JavaScript?
- It calls a function with a given
thisvalue and arguments provided as individual parameters. - It calls a function with a given
thisvalue and arguments provided as an array. - It calls a function with a given
thisvalue and no arguments. - None of the above
What is the difference between the bind(), apply(), and call() methods in JavaScript?
- The
bind()method creates a new function, while theapply()andcall()methods call an existing function. - The
apply()method takes an array of arguments, while thecall()method takes individual arguments. - The
bind()method can only be used with arrow functions, while theapply()andcall()methods can be used with any function. - None of the above
What is a closure in JavaScript?
- A function that has access to the variables of its outer scope, even after the outer scope has finished executing.
- A function that is defined inside another function.
- A function that can be called multiple times.
- None of the above
What is the difference between a global variable and a local variable in JavaScript?
- Global variables are declared outside of any function, while local variables are declared inside a function.
- Global variables are accessible from anywhere in the program, while local variables are only accessible from within the function in which they are declared.
- Global variables can be reassigned, while local variables cannot.
- All of the above