Chapter 5: Statements Flashcards

(23 cards)

1
Q

The let and function are _______ statements—they declare or define variables and
functions

A

declaration

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

function syntax

A

function funcname([arg1 [, arg2 […, argn]]]) {
statements
}

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

Eaxmple of function

A

var f = function(x) { return x+1; } // Expression assigned to a variable

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

if statement syntax

A

if (expression)
statement

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

switch statement syntax

A

switch(n) {
case 1: // Start here if n == 1
// Execute code block #1.
break;
// Stop here
case 2: // Start here if n == 2
// Execute code block #2.
break; // Stop here
case 3: // Start here if n == 3
// Execute code block #3.
break; // Stop here
default: // If all else fails…
// Execute code block #4.
break; // stop here
}

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

Example while loop

A

let count = 0;
while(count < 10) {
console.log(count);
count++;
}

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

do while loop

A

same as java

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

For loop

A

same as java

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

The for/of loop works with _____ objects

A

iterable

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

Examplefor of loop

A

let data = [1, 2, 3, 4, 5, 6, 7, 8, 9], sum = 0;
for(let element of data) {
sum += element;
}
sum

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

If you want to iterate through the properties of an object, you can use
the for/in loop (introduced in §5.4.5), or use for/of with the
_________ method

A

Object.keys()

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

________ returns an array of arrays, where each inner
array represents a key/value pair for one property of the object

A

Object.entries()

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

Are string iterable in javascript

A

yes

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

A for/in loop looks a lot like a for/of loop, with the of keyword
changed to in. While a for/of loop requires an ______ object after
the of, a for/in loop works with ____ object after the in

A

iterable, any

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

Example of for in

A

for(let p in o) { // Assign property names of o to
variable p
console.log(o[p]); // Print the value of each property
}

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

When
working with arrays, you almost always want to use for/of instead
of for/in.

17
Q

Jump statements

A

continue, break, return

18
Q

The yield statement (python) is much like the return statement but is used
only in ES6 generator functions (see §12.3) to produce the next value
in the generated sequence of values without actually ______

19
Q

The _____ statement runs a block of code as if the properties of a
specified object were variables in scope for that code

20
Q

with syntax

A

with (object)
statement

21
Q

JavaScript there is really no reason to use var instead of let.

22
Q

Declare and initialize one or more constants

23
Q

Declare names for values defined in other modules