JavaScript Numbers & Math Operations Quiz

JavaScript
0 Passed
0% acceptance

Master 75 JavaScript questions that cover numeric literals, parsing, formatting, math utilities, and the edge cases every engineer hits when working with numbers.

75 Questions
~150 minutes
1

Question 1

What value is printed when you log the numeric literal 1_000_000 in modern JavaScript?

A
1_000_000
B
1000000
C
1,000,000
D
It throws a SyntaxError
2

Question 2

Which statement correctly declares a numeric literal using exponential notation?

A
const rate = 1e-2;
B
const rate = 1E-2;
C
Both A and B are valid
D
Neither A nor B is valid in JavaScript
3

Question 3

What is the result of typeof 42?

A
"int"
B
"number"
C
"numeric"
D
"integer"
4

Question 4

Which statement about the Number constructor is accurate?

A
new Number(5) creates a primitive number 5
B
Number(5) returns the number primitive 5
C
new Number(5) === 5 evaluates to true
D
Number() always throws if no argument is provided
5

Question 5

What does Number.MAX_SAFE_INTEGER represent?

A
The largest representable floating point number
B
The largest 53-bit integer that can be represented exactly
C
The largest value Math.max can return
D
The maximum value parseInt can produce
6

Question 6

What is the result of 0 / 0 in JavaScript?

A
0
B
Infinity
C
NaN
D
-Infinity
7

Question 7

Which expression evaluates to positive Infinity?

A
Math.log(0)
B
1 / 0
C
Number.MIN_VALUE * 0
D
-Number.MAX_VALUE
8

Question 8

How can you reliably test if a value is NaN?

A
value === NaN
B
Number.isNaN(value)
C
value == NaN
D
typeof value === "NaN"
9

Question 9

What does Number.isFinite(Infinity) return?

A
true
B
false
C
null
D
It throws a TypeError
10

Question 10

Which operation results in -Infinity?

A
-1 / 0
B
Math.floor(-Infinity)
C
Math.log(1)
D
Number.MIN_VALUE * -1
11

Question 11

What is the result of 5 + 2 * 3 according to JavaScript operator precedence?

A
21
B
11
C
17
D
It depends on strict mode
12

Question 12

What does 10 - "3" evaluate to?

A
7
B
"103"
C
NaN
D
10
13

Question 13

What is the outcome of 20 % 6?

A
2
B
4
C
6
D
0
14

Question 14

What does the expression (5 ** 2) ** 3 return?

A
15625
B
125
C
78125
D
It throws because of right associativity
15

Question 15

What value do you get from +"8" + 2?

A
82
B
10
C
NaN
D
"8"
16

Question 16

What does Number("0xF") return?

A
15
B
0
C
"0xF"
D
NaN
17

Question 17

Which expression converts a binary string "1010" to the number 10?

A
Number("1010")
B
parseInt("1010", 2)
C
parseFloat("1010", 2)
D
Math.binary("1010")
18

Question 18

What is the result of Number(true)?

A
1
B
0
C
NaN
D
undefined
19

Question 19

What does parseFloat("12.34px") return?

A
12.34
B
12
C
NaN
D
"12.34px"
20

Question 20

How can you convert the string "005" to the number 5 without leaving leading zeros?

A
parseInt("005", 10)
B
Number("005")
C
+"005"
D
All of the above produce the number 5
21

Question 21

What does parseInt("08", 10) return?

A
0
B
8
C
NaN
D
An exception is thrown
22

Question 22

What does parseInt("0b101", 2) return?

A
5
B
0
C
NaN
D
2
23

Question 23

How does parseFloat handle the string "Infinity"?

A
It returns Infinity
B
It returns 0
C
It returns NaN
D
It throws a RangeError
24

Question 24

What is the output of parseInt("123.45")?

A
123
B
123.45
C
NaN
D
It throws a TypeError
25

Question 25

Which option produces NaN when parsed with parseInt?

A
parseInt("abc", 10)
B
parseInt(" 5", 10)
C
parseInt("-10", 10)
D
parseInt("0xF", 16)
26

Question 26

What does (1234.567).toFixed(2) return?

A
"1234.56"
B
"1,234.57"
C
"1234.57"
D
1234.57
27

Question 27

Which method formats a number using locale-aware separators?

A
number.toString()
B
number.toLocaleString()
C
number.valueOf()
D
number.format()
28

Question 28

What is the output of (0.00012345).toExponential(2)?

A
"1.23e-4"
B
"1.23e-5"
C
"0.00e+0"
D
"1.23E-4"
29

Question 29

How can you format 1234.5 as currency in US locale?

A
1234.5.toFixed(2) + " USD"
B
Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(1234.5)
C
Math.currency(1234.5, "USD")
D
Number.currencyFormat("USD").format(1234.5)
30

Question 30

What does Number(123456789).toString(16) produce?

A
"75bcd15"
B
"0x75BCD15"
C
"123456789"
D
It throws because toString cannot accept a radix
31

Question 31

What does Math.abs(-7) return?

A
-7
B
7
C
NaN
D
undefined
32

Question 32

Which statement about Math.sqrt is correct?

A
Math.sqrt(-1) returns NaN
B
Math.sqrt(-1) returns Infinity
C
Math.sqrt(-1) throws an error
D
Math.sqrt(-1) returns -1
33

Question 33

What is the value of Math.max(3, 7, -2, 9)?

A
9
B
7
C
-2
D
3
34

Question 34

Which expression returns the smallest number among an array of values?

A
Math.min([5, 9, -1])
B
Math.min.apply(null, [5, 9, -1])
C
Math.min.spread([5, 9, -1])
D
Math.minArray([5, 9, -1])
35

Question 35

What does Math.sign(-42) return?

A
1
B
-1
C
0
D
NaN
36

Question 36

What range of values can Math.random() return?

A
0 (inclusive) to 1 (exclusive)
B
0 (inclusive) to 1 (inclusive)
C
-1 to 1
D
0 to 100
37

Question 37

How would you generate a random integer between 0 and 9 (inclusive)?

A
Math.floor(Math.random() * 10)
B
Math.round(Math.random() * 10)
C
Math.ceil(Math.random() * 10)
D
Math.trunc(Math.random())
38

Question 38

Why is Math.random() unsuitable for cryptographic randomness?

A
It always returns 0
B
It may return negative numbers
C
It uses a predictable pseudo-random algorithm
D
It only works in Node.js
39

Question 39

Which approach generates a random integer between a min and max inclusive?

javascript
function randomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min
  }
A
The function is correct as written
B
Use Math.ceil instead of Math.floor
C
Remove the +1 in the multiplier
D
Add Math.random(min, max)
40

Question 40

What is an effective way to simulate a dice roll (1-6)?

A
Math.ceil(Math.random() * 6)
B
Math.floor(Math.random() * 6) + 1
C
Math.round(Math.random() * 5) + 1
D
Math.random(1, 6)
41

Question 41

What is the result of 0.1 + 0.2 === 0.3?

A
true
B
false
C
NaN
D
It throws an error
42

Question 42

How can you compare floating point numbers safely?

A
Compare with === directly
B
Use Math.abs(a - b) < Number.EPSILON
C
Use parseFloat on both numbers first
D
Convert to strings and compare
43

Question 43

What does Number.EPSILON represent?

A
The largest representable double
B
The difference between 1 and the next representable double
C
The smallest positive number
D
The logarithm base e
44

Question 44

Which method can help mitigate floating point rounding issues when dealing with currency?

A
Store values in cents using integers
B
Rely solely on toFixed for correctness
C
Use Math.random to randomize rounding
D
Convert everything to binary first
45

Question 45

What is the effect of Number.parseFloat compared to the global parseFloat?

A
Number.parseFloat is deprecated
B
They behave identically; Number.parseFloat is the modular version
C
Number.parseFloat throws for invalid input
D
The global parseFloat always uses base 16
46

Question 46

Which check correctly identifies integers?

A
Number.isInteger(4.0)
B
Number.isInteger("4")
C
Number.isInteger(4.1)
D
Number.isInteger(NaN)
47

Question 47

What does Number.isFinite("10") return?

A
true
B
false
C
NaN
D
It throws an error
48

Question 48

Which expression detects safe integers?

A
Number.isSafeInteger(2 ** 53 - 1)
B
Number.isSafeInteger(2 ** 53)
C
Number.isSafeInteger(Infinity)
D
Number.isSafeInteger("123")
49

Question 49

How can you test whether a value is NaN using only comparisons?

A
value === value
B
value !== value
C
value == value
D
value >= value
50

Question 50

What does typeof Number("5") return?

A
"number"
B
"string"
C
"object"
D
"undefined"
51

Question 51

What does 2 ** 5 evaluate to?

A
10
B
25
C
32
D
64
52

Question 52

Which expression mirrors Math.pow(4, 3)?

A
4 ^ 3
B
4 ** 3
C
4 *^ 3
D
pow(4,3)
53

Question 53

What is the value of Math.pow(9, 0.5)?

A
3
B
4.5
C
81
D
It throws an error
54

Question 54

Which statement about exponentiation assignment is correct?

A
x **= y is equivalent to x = x ** y
B
x **= y multiplies x by y
C
x **= y is invalid syntax
D
x **= y performs bitwise XOR and assigns back to x
55

Question 55

What is the result of Math.pow(-2, 3)?

A
-8
B
8
C
NaN
D
It throws a RangeError
56

Question 56

What does 10 % 4 return?

A
2
B
0.4
C
4
D
-2
57

Question 57

How does JavaScript define the sign of the modulus result?

A
It takes the sign of the divisor
B
It takes the sign of the dividend
C
It is always positive
D
It is always negative
58

Question 58

What does -7 % 5 evaluate to?

A
2
B
-2
C
0
D
5
59

Question 59

Which snippet computes the remainder safely for floating point numbers?

A
((a % b) + b) % b
B
Math.remainder(a, b)
C
a.mod(b)
D
a % (b % a)
60

Question 60

What is the result of 15 % -4?

A
3
B
-3
C
1
D
-1
61

Question 61

What does Math.round(2.5) return?

A
2
B
3
C
2.5
D
It throws because of ties
62

Question 62

What is the result of Math.round(-1.5)?

A
-2
B
-1
C
0
D
1
63

Question 63

What does Math.ceil(2.01) return?

A
2
B
3
C
2.01
D
It throws a RangeError
64

Question 64

What does Math.floor(-2.01) evaluate to?

A
-2
B
-3
C
-2.01
D
0
65

Question 65

What is the output of Math.trunc(-2.7)?

A
-3
B
-2
C
0
D
2
66

Question 66

What does Math.min() return when called with no arguments?

A
0
B
Infinity
C
-Infinity
D
undefined
67

Question 67

What value does Math.max() return with no arguments?

A
0
B
Infinity
C
-Infinity
D
undefined
68

Question 68

What is the result of Math.max(...[1, 5, 2])?

A
5
B
2
C
1
D
It throws because arrays cannot be spread
69

Question 69

What does Math.min(Infinity, 42, -5) return?

A
-5
B
42
C
Infinity
D
NaN
70

Question 70

What is the outcome of Math.max(-10, -Infinity, -2)?

A
-Infinity
B
-10
C
-2
D
0
71

Question 71

What value results from Number((1.005).toFixed(2))?

A
1
B
1.01
C
1.00
D
It throws a RangeError
72

Question 72

What does Number("") evaluate to?

A
0
B
NaN
C
null
D
undefined
73

Question 73

What does Number.isNaN(parseInt("foo", 10)) return?

A
true
B
false
C
null
D
It throws a SyntaxError
74

Question 74

What is the result of Number.isFinite(parseFloat("Infinity"))?

A
true
B
false
C
NaN
D
It throws an error
75

Question 75

What does Math.min(1, NaN, 3) return?

A
1
B
3
C
NaN
D
-Infinity

QUIZZES IN JavaScript