JS-Dev-101 practice question 19 of 25

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

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

JavaScript has only one type of number, which is Number. Unlike other programming languages, it does not have distinct types for integers, floats, doubles, or decimals. All numbers are implemented as 64-bit floating-point values according to the IEEE 754 standard. The variable pi is assigned a floating-point literal, which falls under the Number primitive data type.

Why Incorrect

A. Float: This is a concept for a type of number, but it is not a distinct primitive data type in the JavaScript language itself.
B. Double: Similar to Float, this describes the precision of a number but is not a formal JavaScript data type. All numbers are effectively doubles.
C. Decimal: This is not a primitive data type in JavaScript. While there are libraries for handling high-precision decimals, it's not a native type.

References

1. MDN Web Docs, "JavaScript data types and data structures", Section: "Number type". States, "The Number numeric type has exactly one type: a double-precision 64-bit binary format IEEE 754 value... There is no specific integer type."

2. ECMAScript® 2024 Language Specification, Section 6.1.6, "The Number Type". Defines the Number type as representing all numbers using the "double-precision 64-bit format IEEE 754-2019 value".

Scroll to Top