JS-Dev-101 practice question 16 of 25

Refer to the code below: const pi = 3.1415926; What is the data type of pi?

Full set: 148 questions
Answer options
A: Number Correct answer
B: Float
C: Double
D: Decimal
Correct Answer:
A. Number
Explanation

JavaScript has only one type for all numbers, both integers and floating-point values. This type is called Number. It is based on the IEEE 754 double-precision 64-bit binary format. While the value 3.1415926 is a floating-point number conceptually, its data type in JavaScript is simply Number. The language does not have distinct Float, Double, or Decimal primitive types.

Why Incorrect

B. Float is not a primitive data type in JavaScript. It's a concept used in other languages like Java or C++.
C. Double is not a primitive data type in JavaScript, although the Number type is implemented as a double-precision float.
D. Decimal is not a primitive data type in JavaScript. High-precision decimals require libraries like Decimal.js.

References

1. Mozilla Developer Network (MDN). (2023). JavaScript data types and data structures - Number type. "The Number numeric type represents both integer and floating-point numbers." Retrieved from developer.mozilla.org/en-US/docs/Web/JavaScript/Datastructures#numbertype.

2. ECMA-262, 15th edition, June 2024. 6.1.6.1 The Number Type. "The Number type has exactly 18437736874454810627 (that is, 2^64 - 2^53 + 3) values, representing the double-precision 64-bit format IEEE 754-2019 values..."

3. Stanford University, CS 101. JavaScript Numbers. "JavaScript has one number type: 64-bit floating point. There is no separate integer type."

Scroll to Top