Functions Flashcards

1
Q

What are functions?

A

A JavaScript procedure.

A set of statements that performs a task or calculates a value.

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

How can you use a function?

A

You have to define it somewhere in the scope from which you want to call it.

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

A function consists of the function keyword, followed by __________. ________ enclosed in parentheses, and the _______ enclosed in curly brakets.

A

the function name.
Parameters.
statements.

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

What are Function Expressions?

A

A function without a name. It is an anonymous function.

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

A function expression can have a name inside the function to what?

A

refer to itself

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

When are function expressions convenient over function declarations?

A

When passing a function as an argument to another function.

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

What are the three ways for a function to refer to itself?

A
  1. the function’s name
  2. arguments.callee
  3. An in-scope variable that refers to the function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the two kinds of parameters in functions?

A
  1. Default parameters

2. Rest parameters

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

What is the default parameter for functions?

A

Undefined

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

How can you change the default parameter?

A

By assigning a value to the argument name.
eg.)

function hello (a, b = 1) {
}

The default value is now 1 and not undefined.

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

What is the rest parameter?

A

Allows us to represent an indefinite number of arguments as an array.

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

An arrow function expression lexically binds the ____ value.

A

this

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

Are arrow functions always anonymous?

A

Yes

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

What are the two factors influenced the introduction of arrow functions?

A

Short functions and lexical ‘this’

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

What is the syntax for an function expression?

A

functionName( => code block );

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

JS built-in function: eval() method

A

Evaluates JS code represented as a string.

17
Q

JS built-in function: uneval() method

A

Creates a string representation of the source code of an object.

18
Q

JS built-in function: isFinite() method

A

Determines whether the passed values is a finite number. If needed, the parameter is first converted to a number.

19
Q

JS built-in function: isNaN() method

A

Determines whether a value is NaN or not.

20
Q

JS built-in function: parseFloat() method

A

Parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems)

21
Q

JS built-in function: parseInt() method

A

Parses a string argument and returns an integer of the specified radix.

22
Q

JS built-in function: decodeURI() method

A

Decodes a Uniform Resource Identifier(URI) previously created by encodeURI or by a similar routine.

23
Q

JS built-in function: decodeURIComponent() method

A

Decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine.

24
Q

JS built-in function: encodeURI() method

A

Encodes a Uniform Resource Identifier(URI) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF- 8 encoding of the character (will only be four escape sequences for characters composed of two “surrogate” characters).

25
Q

JS built-in function: encodeURICompoment() method

A

Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two “surrogate” characters).