JavaScript functions Flashcards
(27 cards)
What is a function in JavaScript?
A function is a block of code designed to perform a particular task.
True or False: Functions in JavaScript can return values.
True
What keyword is used to define a function in JavaScript?
The keyword ‘function’ is used to define a function.
Fill in the blank: A function can be invoked using its ______.
name
What is the purpose of the ‘return’ statement in a function?
The ‘return’ statement is used to return a value from a function.
What is a function expression?
A function expression is a function that is defined within an expression and can be stored in a variable.
True or False: JavaScript functions are first-class objects.
True
What is an anonymous function?
An anonymous function is a function that does not have a name.
Multiple Choice: Which of the following is a way to define a function? A) function myFunction() {} B) var myFunction = function() {} C) Both A and B
C) Both A and B
What is a callback function?
A callback function is a function passed into another function as an argument to be executed later.
Fill in the blank: A function can take ______, which are values passed to it when invoked.
parameters
What is the difference between a function declaration and a function expression?
A function declaration is defined with the ‘function’ keyword and can be called before it’s defined, while a function expression is defined within an expression and cannot be called before it’s defined.
True or False: JavaScript allows functions to be nested within other functions.
True
What does the ‘this’ keyword refer to inside a function?
‘This’ refers to the object that is currently executing the function.
Multiple Choice: What will be the output of the following code: console.log(typeof myFunc); A) ‘function’ B) ‘object’ C) ‘undefined’
A) ‘function’
What is a pure function?
A pure function is a function that always produces the same output for the same input and has no side effects.
Fill in the blank: In JavaScript, functions can be assigned to ______.
variables
What is a higher-order function?
A higher-order function is a function that takes one or more functions as arguments or returns a function as its result.
True or False: JavaScript functions can be recursive.
True
What is the purpose of the ‘arguments’ object in a function?
The ‘arguments’ object is an array-like object that contains the values of the arguments passed to the function.
Multiple Choice: Which of the following is NOT a method to invoke a function? A) Directly B) Using call() C) Using new
C) Using new
What is a closure in JavaScript?
A closure is a function that retains access to its lexical scope, even when the function is executed outside that scope.
Fill in the blank: A function defined inside another function has access to the ______ of its parent function.
variables