Operators and loops Flashcards

1
Q

List several common arithmetic operators

A

+ a = c + b
% a = b % c
* a = b * c
++ a++ would add 1 to a
– a– would subtract 1 from a
+= a += b would add b to a
-= a -= b would subtract b from a
*= a *= b multiplies a by b
/= a /= b divides a by b

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

What are some common string operators

A

+ “string1” + “string”
${} let name = ‘${firstName} ${lastName}’;

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

what is the difference between == and ===

A

A == B cpmpares the values of A and B
A === B compares the value and type of A and B

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

How is not equal value and not equal value and type written?

A

not equal value A != B
not equal value and type A !== B

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

Write an example of each of the three logical operators used in JS

A

A === 10 && B === 20
where && is “and”
A === 15 !! B === 5
where !! is “and”
!( a === b ) where ! is “not”

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

What are the conditional operators used in JS

A

If else elseif endif

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

What is te syntax of a conditional statement after the If else or elseif

A

The statement to be executed are enclosed in curly brackets. For example
If ( a <= 100 {
do this( )
}
else {
do this ( )
}

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

What is the ternary operator

A

let a =100
let output =
a <= 100
? ‘${a} is less than 100
: ‘${a} is not less than 100’;
console.log(output);

so if the statement is true everything after the ? runs
if the statement is false everything after : runs even if it is another if statement

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

How are Ternary operators chained?

A

let a = 100
let output =
a <= 100? ‘${a} is less than 100’
: a >= 100
? ‘{a} is greater than 99’
: ‘{a} is less than 100

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

ive an example of the SWITCH statement in JS

A

let name = ‘Bob’;
switch (name) {
case ‘Bill” :
console.log(“it is Bob”);
case “Google”:
console.log(“it is Google”;
case “Bob”:
console.log(“it is Bob”);
default:
console.log({name});

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

What are the loop types in JS?

A

Do
Do While
For

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

List a simple FOR loop

A

for (let counter = 0; counter <= 10; counter++) {
console.log(counter);
}

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

List a simple do while loop

A

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

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

list a simple while loop

A

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

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