Numbers Knowledge Flashcards
‘8’ == 8; ‘8’ === 8;
true false
0.1 + 0.2
0.30000000000000004
Return the biggest number
What happens with bigger numbers?
Number.MAX_VALUE;
// 1.7976931348623157e+308
They are returned as Infinity
‘5’ + 1
‘1’ + 5
‘51’
‘15’
‘51’ > 6
6 < ‘51’
true
true
‘5’ * 1
‘5’ / ‘1’
5
5
‘12’ < ‘9’
true it only converts the first character of each if both sides are strings
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.
use an XOR gate ^ const a = 5; // 00000000000000000000000000000101 const b = 3; // 00000000000000000000000000000011
(a ^ b); // 00000000000000000000000000000110
const findOdd = (xs) => xs.reduce((a, b) => a ^ b);
Get infinity (2 ways)
Infinity
1/0
Evaluate Number(x) when x equals:
undefined
null
true and false
‘ 5 ‘
’ ‘
’ 2 hello ‘
NaN
0
1 and 0
5
0
NaN.
Evaluate:
‘2’ + 1
2 + ‘1’
‘21’
‘21’
Evlaluate:
2 + 2 + ‘1’
‘1’ + 2 + 2
41
122
Evaluate:
“6” / “2”
‘6’ - 2
‘a’ - 2
3
4
NaN
(+ is the only operator that will implicitly convert to strings. The others will only implicitly convert to numbers)
Evaluate the following with the + unary operator:
+2
+(-2)
+null
+undefined
+“true”
+true
It does the same thing as Number() essentially
2
-2
0
NaN
NaN
1
Evaluate a, b and c:
let a, b, c;
a = b = c = 2 + 2;
4
4
4
(but don’t do it)