How do you define a function in JavaScript?
function myFunc() {}
def myFunc() {}
function = myFunc {}
func myFunc() {}
What is the right output for the code below?
function greet(name) {
console.log(`${name}, Welcome to GFG!`);
}
greet(Geek);
Geek, Welcome to GFG!
name, Welcome to GFG!
No output
Compilation error
Which of the following is a valid arrow function?
const myFunc = => {}
const myFunc = () => {}
const myFunc => () {}
function => () {}
What is a closure in JavaScript?
A function combined with its lexical scope
A function that cannot be called outside its block
A function with no arguments
A function with no return value
What is the output of the following code?
(function () {
console.log("IIFE");
})();
"IIFE"
undefined
Error
null
Which keyword is used to refer to the current function context in JavaScript?
self
this
context
bind
Which method is used to bind the 'this' context of a function explicitly?
call
apply
bind
All of the above
What is recursion in JavaScript?
A function calling another function
A function calling itself
A function with no return value
A function executed immediately after declaration
What is the purpose of the rest parameter (...args) in a function?
To pass unlimited arguments as an array
To combine two arrays
To stop the function execution
To return the first argument only
What will the following code output?
const add = (a, b) => a + b;
console.log(add(5));
5
NaN
Error
undefined
There are 10 questions to complete.