JavaScript functions Flashcards

(27 cards)

1
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a function in JavaScript?

A

A function is a block of code designed to perform a particular task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or False: Functions in JavaScript can return values.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What keyword is used to define a function in JavaScript?

A

The keyword ‘function’ is used to define a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fill in the blank: A function can be invoked using its ______.

A

name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of the ‘return’ statement in a function?

A

The ‘return’ statement is used to return a value from a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a function expression?

A

A function expression is a function that is defined within an expression and can be stored in a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or False: JavaScript functions are first-class objects.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an anonymous function?

A

An anonymous function is a function that does not have a name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

C) Both A and B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a callback function?

A

A callback function is a function passed into another function as an argument to be executed later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Fill in the blank: A function can take ______, which are values passed to it when invoked.

A

parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between a function declaration and a function expression?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or False: JavaScript allows functions to be nested within other functions.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the ‘this’ keyword refer to inside a function?

A

‘This’ refers to the object that is currently executing the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Multiple Choice: What will be the output of the following code: console.log(typeof myFunc); A) ‘function’ B) ‘object’ C) ‘undefined’

A

A) ‘function’

17
Q

What is a pure function?

A

A pure function is a function that always produces the same output for the same input and has no side effects.

18
Q

Fill in the blank: In JavaScript, functions can be assigned to ______.

19
Q

What is a higher-order function?

A

A higher-order function is a function that takes one or more functions as arguments or returns a function as its result.

20
Q

True or False: JavaScript functions can be recursive.

21
Q

What is the purpose of the ‘arguments’ object in a function?

A

The ‘arguments’ object is an array-like object that contains the values of the arguments passed to the function.

22
Q

Multiple Choice: Which of the following is NOT a method to invoke a function? A) Directly B) Using call() C) Using new

23
Q

What is a closure in JavaScript?

A

A closure is a function that retains access to its lexical scope, even when the function is executed outside that scope.

24
Q

Fill in the blank: A function defined inside another function has access to the ______ of its parent function.

25
What is the difference between 'call()' and 'apply()' methods in functions?
'call()' takes arguments individually, while 'apply()' takes arguments as an array.
26
True or False: You can use the 'new' keyword to create an instance of a function.
True
27
What is the significance of the 'return' keyword in a function?
The 'return' keyword is used to specify the value that will be returned from the function.