foundations Flashcards

1
Q

alert( 5 % 2 );
alert( 8 % 3 );
alert( 8 % 4 );

A

// 1, the remainder of 5 divided by 2
// 2, the remainder of 8 divided by 3
// 0, the remainder of 8 divided by 4

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

let x = 0.2 + 0.1;
returns?

A

0.300000004

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

let x = 0.2 + 0.1
returns 0.300000004

How to solve this problem to return 0.3?

A

To solve the problem above, it helps to multiply and divide:

let x = (0.2 * 10 + 0.1 * 10) / 10;

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

let x = “10”;
let y = “20”;
let z = x + y;

returns?

A

1020

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

let x = 10;
let y = “20”;
let z = x + y;

returns?

A

1020
concatination

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

let x = “10”;
let y = 20;
let z = x + y;

returns?

A

1020
concatenation

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

let x = 10;
let y = 20;
let z = “The result is: “ + x + y;

returns?

A

1020

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

let x = 10;
let y = 20;
let z = “30”;
let result = x + y + z;

returns

A

3030

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

JavaScript will try to convert _____ to numbers in all numeric operations:

A

strings

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

JavaScript will try to convert strings to _______ in all numeric operations:

A

numbers

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

JavaScript will try to convert strings to numbers in all numeric operations:

True or false

A

true

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

let x = “100”;
let y = “10”;
let z = x + y;
let z = x - y;
let z = x / y;
let z = x * y;

A

10010
90
10
1000

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

let x = 100 / “Apple”;
returns?

A

NAN

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

You can use the global JavaScript function_______ to find out if a value is a not a number:

A

isNaN()

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

let x = NaN;
let y = 5;
let z = x + y;

z returns?

A

NAN

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

let x = NaN;
let y = “5”;
let z = x + y;

z returns?

A

NaN5

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

NaN is a _____:

A

Number

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

typeof NaN returns _______:

A

Number

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

Division by 0 (zero) also generates ___________:

A

Infinity

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

let x = 2 / 0;
let y = -2 / 0;

A

infinity
-infinity

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

Infinity is a _____:

A

number

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

typeof Infinity returns ______.

23
Q

let x = 123;
let y = new Number(123);

x returns
y returns

A

number
object

24
Q

let x = 500;
let y = new Number(500);
x==y returns

25
let x = 500; let y = new Number(500); x===y returns
false
26
let x = new Number(500); let y = new Number(500); x==y returns?
false
27
let x = new Number(500); let y = new Number(500); x===y returns?
false
28
alert( 2 ** 2 ); alert( 2 ** 3 ); alert( 2 ** 4 );
// 2² = 4 // 2³ = 8 // 2⁴ = 16
29
alert('1' + 2 + 2);
// "122" and not "14"
30
alert( 6 - '2' ); alert( '6' / '2' );
// 4, converts '2' to a number // 3, converts both operands to numbers
31
let x = 1; alert( +x );
// 1
32
et y = -2; alert( +y );
// -2
33
// Converts non-numbers alert( +true ); alert( +"" );
// 1 // 0
34
let apples = "2"; let oranges = "3"; alert( +apples + +oranges );
// both values converted to numbers before the binary plus // 5
35
let apples = "2"; let oranges = "3"; // both values converted to numbers before the binary plus alert( +apples + +oranges ); // 5 write out the longer variant
// alert( Number(apples) + Number(oranges) ); // 5
36
alert( Number(apples) + Number(oranges) ); // 5 write shorter version
alert( +apples + +oranges );
37
let a = 1; let b = 2; let c = 3 - (a = b + 1); alert( a ); alert( c );
// 3 // 0
38
let a, b, c; a = b = c = 2 + 2; alert( a ); alert( b ); alert( c );
4 4 4
39
let n = 2; n = n + 5; n = n * 2; write out short version
n += 5; // now n = 7 (same as n = n + 5) n *= 2; // now n = 14 (same as n = n * 2)
40
let n = 2; n *= 3 + 5; alert( n );
// right part evaluated first, same as n *= 8 16
41
let counter = 2; counter++; alert( counter ); // returns
3
42
write shorter let counter = counters + 1
counter++
43
let counter = 1; let a = ++counter; alert(a); // returns
2
44
let counter = 1; let a = counter++; alert(a); // returns
1
45
let counter = 0; counter++; ++counter; alert( counter ); //
2 the lines above did the same
46
let counter = 0; alert( ++counter ); // returns
1
47
let counter = 0; alert( counter++ ); //
0
48
let counter = 1; alert( 2 * ++counter ); // returns
4
49
let counter = 1; alert( 2 * counter++ ); // returns
2
50
let a = (1 + 2, 3 + 4); alert( a ); //
7 (the result of 3 + 4)
51
The comma operator allows us to evaluate several expressions, dividing them with a comma ,. Each of them is evaluated but only __________ one is returned.
the result of the last
52
console.log("" + 1 + 0); returns?
10
53
console.log("" - 1 + 0);
-1