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 ______.

A

number

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

A

true

25
Q

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

A

false

26
Q

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

x==y returns?

A

false

27
Q

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

x===y returns?

A

false

28
Q

alert( 2 ** 2 );
alert( 2 ** 3 );
alert( 2 ** 4 );

A

// 2² = 4
// 2³ = 8
// 2⁴ = 16

29
Q

alert(‘1’ + 2 + 2);

A

// “122” and not “14”

30
Q

alert( 6 - ‘2’ );
alert( ‘6’ / ‘2’ );

A

// 4, converts ‘2’ to a number
// 3, converts both operands to numbers

31
Q

let x = 1;
alert( +x );

A

// 1

32
Q

et y = -2;
alert( +y );

A

// -2

33
Q

// Converts non-numbers
alert( +true );
alert( +”” );

A

// 1
// 0

34
Q

let apples = “2”;
let oranges = “3”;

alert( +apples + +oranges );

A

// both values converted to numbers before the binary plus

// 5

35
Q

let apples = “2”;
let oranges = “3”;

// both values converted to numbers before the binary plus
alert( +apples + +oranges ); // 5

write out the longer variant

A

// alert( Number(apples) + Number(oranges) ); // 5

36
Q

alert( Number(apples) + Number(oranges) ); // 5

write shorter version

A

alert( +apples + +oranges );

37
Q

let a = 1;
let b = 2;

let c = 3 - (a = b + 1);

alert( a );
alert( c );

A

// 3
// 0

38
Q

let a, b, c;

a = b = c = 2 + 2;

alert( a );
alert( b );
alert( c );

A

4
4
4

39
Q

let n = 2;
n = n + 5;
n = n * 2;

write out short version

A

n += 5; // now n = 7 (same as n = n + 5)
n *= 2; // now n = 14 (same as n = n * 2)

40
Q

let n = 2;

n *= 3 + 5;

alert( n );

A

// right part evaluated first, same as n *= 8

16

41
Q

let counter = 2;
counter++;
alert( counter ); // returns

A

3

42
Q

write shorter
let counter = counters + 1

A

counter++

43
Q

let counter = 1;
let a = ++counter;

alert(a); // returns

A

2

44
Q

let counter = 1;
let a = counter++;

alert(a); // returns

A

1

45
Q

let counter = 0;
counter++;
++counter;
alert( counter ); //

A

2

the lines above did the same

46
Q

let counter = 0;
alert( ++counter ); // returns

A

1

47
Q

let counter = 0;
alert( counter++ ); //

A

0

48
Q

let counter = 1;
alert( 2 * ++counter ); // returns

A

4

49
Q

let counter = 1;
alert( 2 * counter++ ); // returns

A

2

50
Q

let a = (1 + 2, 3 + 4);

alert( a ); //

A

7 (the result of 3 + 4)

51
Q

The comma operator allows us to evaluate several expressions, dividing them with a comma ,. Each of them is evaluated but only __________ one is returned.

A

the result of the last

52
Q

console.log(“” + 1 + 0);
returns?

A

10

53
Q

console.log(“” - 1 + 0);

A

-1