JS Basic Flashcards

1
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
2
Q

True or False: Functions in JavaScript can be assigned to variables.

A

True

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

Fill in the blank: A function can be defined using the ______ keyword.

A

function

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

What is the syntax to declare a function named ‘myFunction’?

A

function myFunction() {}

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

What are function parameters?

A

Function parameters are the variables listed within the parentheses in a function declaration.

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 exit a function and return a value to the caller.

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

What type of function is defined using the arrow syntax?

A

Arrow function

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

True or False: Functions can be nested inside other functions.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
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
10
Q

How do you invoke a function named ‘calculate’?

A

calculate();

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

What is a higher-order function?

A

A higher-order function is a function that takes another function as an argument or returns a function as a result.

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

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

A

‘this’ refers to the object that is executing the current function.

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

What is the difference between function declaration and function expression?

A

Function declarations are hoisted, while function expressions are not.

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

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

A

function name; function expression

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

What is an Immediately Invoked Function Expression (IIFE)?

A

An IIFE is a function that runs as soon as it is defined.

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

True or False: You can have multiple return statements in a single function.

17
Q

What is the purpose of the ‘arguments’ object in functions?

A

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

18
Q

What does the term ‘scope’ refer to in JavaScript?

A

Scope refers to the accessibility of variables and functions in different parts of the code.

19
Q

What is a default parameter in a function?

A

A default parameter is a parameter that has a default value if no value is passed.

20
Q

What is closure in JavaScript?

A

Closure is a feature where an inner function has access to the outer function’s variables even after the outer function has returned.