JavaScript Numbers MCQ

1. What types of numbers does JavaScript support?

a) Integers and floats as distinct types
b) Only integers
c) Only floats
d) A single number type, which includes integers and floats

Answer:

d) A single number type, which includes integers and floats

Explanation:

JavaScript has only one type of number, which can be written with or without decimals, including integers and floating-point numbers.

2. How are JavaScript numbers stored internally?

a) As 32-bit floating-point numbers
b) As 64-bit floating-point numbers
c) As separate integer and float types
d) In hexadecimal format

Answer:

b) As 64-bit floating-point numbers

Explanation:

JavaScript numbers are always stored as double precision floating point numbers (64-bit), following the international IEEE 754 standard.

3. What is the precision limit of integers in JavaScript?

a) Up to 10 digits
b) Up to 15 digits
c) Up to 17 digits
d) Unlimited

Answer:

b) Up to 15 digits

Explanation:

Integers in JavaScript are accurate up to 15 digits.

4. Which of the following demonstrates JavaScript's floating point arithmetic inaccuracy?

a) 0.1 + 0.2 == 0.3
b) 1 / 0 == Infinity
c) 0.2 * 10 + 0.1 * 10
d) 999999999999999 + 1

Answer:

a) 0.1 + 0.2 == 0.3

Explanation:

Floating point arithmetic in JavaScript is not always 100% accurate. For example, 0.1 + 0.2 does not precisely equal 0.3 due to the way floating-point numbers are represented in the language.

5. What is the result of adding a number and a string in JavaScript?

a) An error
b) Addition of the two values
c) A string concatenation
d) NaN

Answer:

c) A string concatenation

Explanation:

In JavaScript, using the + operator between a number and a string results in string concatenation.

6. What does the JavaScript operation 100 / "Apple" return?

a) 0
b) An error
c) "NaN"
d) "100Apple"

Answer:

c) "NaN"

Explanation:

Performing arithmetic operations with non-numeric strings in JavaScript, like 100 / "Apple", results in NaN (Not a Number).

7. What is the output of typeof NaN in JavaScript?

a) "NaN"
b) "undefined"
c) "object"
d) "number"

Answer:

d) "number"

Explanation:

In JavaScript, the typeof NaN returns "number", indicating that NaN, while representing 'Not a Number', is technically of the type number.

8. What value does JavaScript return when performing calculations exceeding the largest representable number?

a) NaN
b) An error
c) Undefined
d) Infinity

Answer:

d) Infinity

Explanation:

JavaScript returns 'Infinity' when calculations exceed the largest possible number, such as division by zero or exceedingly large exponentiations.

9. How does JavaScript interpret numeric constants preceded by "0x"?

a) As decimal numbers
b) As binary numbers
c) As octal numbers
d) As hexadecimal numbers

Answer:

d) As hexadecimal numbers

Explanation:

Numeric constants preceded by "0x" are interpreted as hexadecimal numbers in JavaScript.

10. What is the result of using new Number(123) in JavaScript?

a) Creates a number primitive
b) Creates a number object
c) Syntax error
d) Converts a string to a number

Answer:

b) Creates a number object

Explanation:

Using new Number(123) creates a Number object, which is different from a number primitive. Number objects can produce unexpected results compared to number primitives.

11. What happens when you add two numeric strings in JavaScript?

a) The strings are concatenated
b) The values are added as numbers
c) It results in an error
d) It returns NaN

Answer:

a) The strings are concatenated

Explanation:

When adding two numeric strings in JavaScript, the strings are concatenated instead of being added as numbers.

12. How can you check if a value is NaN in JavaScript?

a) Using the isNan() function
b) Comparing the value to NaN
c) Using the typeof operator
d) Checking if the value is less than Infinity

Answer:

a) Using the isNan() function

Explanation:

The global JavaScript function isNaN() is used to determine if a value is NaN.

13. What is the maximum number of decimals that JavaScript can handle in a number?

a) 10 decimals
b) 15 decimals
c) 17 decimals
d) Unlimited decimals

Answer:

c) 17 decimals

Explanation:

The maximum number of decimals JavaScript can handle in a number is 17.

14. In JavaScript, what is the result of dividing a number by zero?

a) 0
b) NaN
c) An error is thrown
d) Infinity

Answer:

d) Infinity

Explanation:

Dividing a number by zero in JavaScript results in Infinity.

15. How does JavaScript handle hexadecimal number representation?

a) By prefixing with "#"
b) By prefixing with "0x"
c) By using the hex() function
d) Automatically, without any prefix

Answer:

b) By prefixing with "0x"

Explanation:

In JavaScript, hexadecimal numbers are represented by prefixing them with "0x".

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top