Numbers Knowledge Flashcards

1
Q

‘8’ == 8; ‘8’ === 8;

A

true false

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

0.1 + 0.2

A

0.30000000000000004

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

Return the biggest number

What happens with bigger numbers?

A

Number.MAX_VALUE;

// 1.7976931348623157e+308

They are returned as Infinity

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

‘5’ + 1

‘1’ + 5

A

‘51’

‘15’

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

‘51’ > 6

6 < ‘51’

A

true

true

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

‘5’ * 1

‘5’ / ‘1’

A

5

5

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

‘12’ < ‘9’

A

true it only converts the first character of each if both sides are strings

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

Given an array of integers, find the one that appears an odd number of times.

There will always be only one integer that appears an odd number of times.

A
use an XOR gate ^
const a = 5; // 00000000000000000000000000000101
const b = 3; // 00000000000000000000000000000011

(a ^ b); // 00000000000000000000000000000110

const findOdd = (xs) => xs.reduce((a, b) => a ^ b);

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

Get infinity (2 ways)

A

Infinity

1/0

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

Evaluate Number(x) when x equals:

undefined
null
true and false
‘ 5 ‘

’ ‘

’ 2 hello ‘

A

NaN

0

1 and 0

5

0

NaN.

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

Evaluate:

‘2’ + 1

2 + ‘1’

A

‘21’

‘21’

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

Evlaluate:

2 + 2 + ‘1’

‘1’ + 2 + 2

A

41

122

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

Evaluate:

“6” / “2”

‘6’ - 2

‘a’ - 2

A

3

4

NaN

(+ is the only operator that will implicitly convert to strings. The others will only implicitly convert to numbers)

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

Evaluate the following with the + unary operator:

+2

+(-2)

+null

+undefined

+“true”

+true

A

It does the same thing as Number() essentially

2

-2

0

NaN

NaN

1

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

Evaluate a, b and c:

let a, b, c;

a = b = c = 2 + 2;

A

4

4

4

(but don’t do it)

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

Evaluate a and b:

let counter = 1;

let a = ++ counter

let b = counter++

A

a = 2 (add 1 to counter, then assign it to a)

b= 1 (assign counter to b, then add 1 to counter)

17
Q

Evaluate

let counter = 0;

console. log(2 * counter++);
console. log(2 * ++counter);

A

0

4

18
Q

For readability, instead of:

let counter = 1;

alert( 2 * counter++ );

what should you do?

A

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

19
Q

What is returned from:

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

a;

A

// 7 (the result of 3 + 4)

Each of them is evaluated but only the result of the last one is returned.

20
Q

What is returned from:

let a = 1 + 2, 3 + 4;

and what is returned from:

a;

A

//syntax error

21
Q

What is returned from:

true + false

A

1

+ converts them to numbers

1 + 0

22
Q

What is returned from:

” -9 “ - 5

A

-14

it first removes blank spaces from the beginning and end

23
Q

This returns 12, make it return 3

let a = prompt("First number?", 1);
let b = prompt("Second number?", 2);

alert(a + b); // 12

A

let a = +prompt(“First number?”, 1);
let b = +prompt(“Second number?”, 2);

alert(a + b); // 3

OR

let a = prompt("First number?", 1);
let b = prompt("Second number?", 2);

alert(+a + +b); // 3

24
Q

Boolean(0)

Boolean(‘0’)

0 == ‘0’

A

False

True

True

25
Q

‘2’ > ‘12’

A

true

(both are strings so 2 > 1)

26
Q

‘12’ < 2

A

false

(‘12’ is converted to a number when compared to a number)

27
Q

alert( null > 0 );
alert( null == 0 );
alert( null >= 0 );

A

// (1) false

// (2) false (with equality, null is not converted to a number)

// (3) true (with comparisons, null is converted to a number)

28
Q

What is returned from:

123.toString()

?

A

Syntax error.

it works with (123).toString()

or

let aNumber = 123

aNumber.toString()

Why? [incomplete]

29
Q

What is an integer property?

A

a string that can be converted to a number and back to a string without changing

alert( String(Math.trunc(Number(“49”))) ); // “49”, same, integer property

alert( String(Math.trunc(Number(“+49”))) ); // “49”, not same “+49” ⇒ not integer property

alert( String(Math.trunc(Number(“1.2”))) ); // “1”, not same “1.2” ⇒ not integer property

30
Q

What is the value of x in the following:

let x = 123_123

let x = 123__123

A

123123
error

31
Q

Write 1123000000 in exponential form

write .0123 in exponential form

A

1.234e9
1.23e-2

32
Q

Convert numbers from binary

Convert numbers from octal

A

let a = 0b11111111; // binary form of 255

let b = 0o377; // octal form of 255

alert( a == b ); // true, the same number 255 at both sides

33
Q

Shorthand for hexadecinal numbers

A

0x

console.log(0xff);

34
Q

Convert numbers to a specific base numbering system as a string

A

(15).toString(16)

35
Q

Write a function to round number to specific number of decimal places using Math.round()

A

Math.round() just rounds to the nearest integer. So:

num = 1.23456

Math.round(num * 100) / 100 ; // 1.23456 -> 123.456 -> 123 -> 1.23

A function that would do it might look like:

function roundToFloat(inputNumber, numberOfDecimalPlaces) {

return Math.round(inputNumber * (10**(numberOfDecimalPlaces))) / 10**(numberOfDecimalPlaces);

}

36
Q

What is returned from:

1e500

A

infinity

37
Q

What does this return (16 nines):

9999999999999999

A

10000000000000000
Javascript doesn’t have integers, only 64-bit floats - and you’ve ran out of floating-point precision.

38
Q

+‘Infinity’ == Infinity

A

true

39
Q

What is returned from 1e(variable)

A

an error

to take the power of a variable, use **