JS week 1 day 3 Flashcards

1
Q

Why do we log things to the console?

A

The JavaScript console is a debugging tool. It is where the browser prints errors and warnings as they occur in your JavaScript code.

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

How is a method different from any other function?

A

A function lives on its own. A method is a function associated with an object property. A function can be called directly by its name. A method consists of a code that can be called by the name of its object and its method name using dot notation or square bracket notation.

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

How do you remove the last element from an array?

A

using .pop method

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

How do you round a number down to the nearest integer?

A

using Math.floor method

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

How do you round a number down to the nearest integer?

A

using Math.floor() method

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

How do you generate a random number?

A

using Math.random() method

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

How do you delete an element from an array?

A

using .splice method()

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

How do you append an element to an array?

A

using .push() method

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

How do you break a string up into an array?

A

using .split() method

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

Do string methods change the original string? How would you check if you weren’t sure?

A

The split() method does not change the original string because JavaScript strings are immutable. To check we can either check documentation or use console.log()

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

Roughly how many array methods are there according to the MDN Web docs?

A

38 methods

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

Is the return value of a function or method useful in every situation?

A

Some functions don’t return any value (For example: void or undefined). Generally, a return value is used where the function is an intermediate step in a calculation of some kind.

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

Roughly how many array methods are there according to the MDN Web docs?

A

36 methods

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

Give 6 examples of comparison operators.

A

===, >, =, <=, !===

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

What is the purpose of an if statement?

A

if statements are used to check if condition is true or false.

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

What data type do comparison expressions evaluate to?

A

boolean

17
Q

Describe the syntax (structure) of an if statement.

A

if ( condition) {
return
}

18
Q

What are the three logical operators?

A

&& and, || or, ! not

19
Q

Describe the syntax (structure) of an if statement.

A

if keyword, condition inside parenthesis, opening curly brace, code to execute if value is true or false, closing curly brace

20
Q

What does the ++ increment operator do?

A

increments by 1

21
Q

What is the purpose of a loop?

A

Loops check a condition; if it returns true, code block will run and will repeat until condition returns false.

22
Q

What is the purpose of a condition expression in a loop?

A

The condition is an expression that is evaluated once before every iteration. The statement inside the loop is executed only when the condition evaluates to true. The loop is terminated if the condition evaluates to false.

23
Q

What does “iteration” mean in the context of loops?

A

Iteration is when the same procedure is repeated multiple times.

24
Q

When does the condition expression of a while loop get evaluated?

A

as long as the condition in the parentheses is true.

25
Q

When does the initialization expression of a for loop get evaluated?

A

The initialization expression initializes the loop. The initialization expression is executed only once when the loop starts.

26
Q

When does the condition expression of a for loop get evaluated?

A

as long as the counter is less than the total number specified.

27
Q

When does the condition expression of a for loop get evaluated?

A

after the initialization expression.

28
Q

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break keyword

29
Q

What does the ++ increment operator do?

A

increments (adds one to) its operand and returns a value

30
Q

How do you iterate through the keys of an object?

A

for in loop

31
Q

What is Array.prototype.filter useful for?

A

The filter() method creates a new array with all elements that pass the test implemented by the provided function. If we need to work with filtered values from a given array.

32
Q

What is Array.prototype.map useful for?

A

The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.