JavaScript Data Types MCQ

1. What are the basic data types in JavaScript?

a) String, Number, Boolean, Object, Function
b) String, Number, Boolean, Object, Undefined, Null
c) String, Number, Bigint, Boolean, Undefined, Null, Symbol, Object
d) String, Integer, Float, Boolean, Array

Answer:

c) String, Number, Bigint, Boolean, Undefined, Null, Symbol, Object

Explanation:

JavaScript has eight basic data types, including String, Number, Bigint, Boolean, Undefined, Null, Symbol, and Object.

2. Which JavaScript data type is used to represent large integers?

a) Integer
b) Float
c) Bigint
d) Double

Answer:

c) Bigint

Explanation:

Bigint is a JavaScript data type introduced to handle integers larger than those that can be represented by the Number type.

3. In JavaScript, how are objects typically written?

a) Between parentheses ()
b) Between square brackets []
c) Between curly braces {}
d) Between angle brackets <>

Answer:

c) Between curly braces {}

Explanation:

JavaScript objects are written with curly braces, with properties defined as name:value pairs.

4. What will be the output of typeof 3.14 in JavaScript?

a) "integer"
b) "float"
c) "number"
d) "decimal"

Answer:

c) "number"

Explanation:

In JavaScript, both integers and floating point numbers are considered as "number" type.

5. What is the default value and type of an uninitialized variable in JavaScript?

a) null, "null"
b) 0, "number"
c) "", "string"
d) undefined, "undefined"

Answer:

d) undefined, "undefined"

Explanation:

A variable without a value in JavaScript has the value undefined and the type is also undefined.

6. How can you write an array in JavaScript?

a) Using curly braces {}
b) Using parentheses ()
c) Using square brackets []
d) Using angle brackets <>

Answer:

c) Using square brackets []

Explanation:

JavaScript arrays are written with square brackets, with items separated by commas.

7. What does the typeof operator return for an empty string in JavaScript?

a) "undefined"
b) "null"
c) "string"
d) "empty"

Answer:

c) "string"

Explanation:

An empty string in JavaScript is still of type "string".

8. What are the possible values of a Boolean type in JavaScript?

a) 0 and 1
b) Yes and No
c) True and False
d) true and false

Answer:

d) true and false

Explanation:

In JavaScript, the Boolean type can only have two values: true or false.

9. Which of the following is an example of an Object data type in JavaScript?

a) "Hello, World!"
b) 42
c) ["Apple", "Banana", "Cherry"]
d) {name: "John", age: 30}

Answer:

d) {name: "John", age: 30}

Explanation:

An Object in JavaScript is written with curly braces and consists of properties defined as name:value pairs.

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

a) Error
b) NaN
c) The number as a string
d) Concatenation of the number and string

Answer:

d) Concatenation of the number and string

Explanation:

When adding a number and a string, JavaScript will treat the number as a string and concatenate them.

11. Which data type is used in JavaScript to handle text?

a) Char
b) Text
c) String
d) Varchar

Answer:

c) String

Explanation:

A string in JavaScript is used to handle text and can be written with either single or double quotes.

12. How are JavaScript numbers stored?

a) As integers only
b) As floating-point numbers
c) As strings
d) As binary values

Answer:

b) As floating-point numbers

Explanation:

All JavaScript numbers are stored as decimal numbers (floating point), regardless of whether they have decimals or not.

13. What does typeof operator return for an array in JavaScript?

a) "array"
b) "object"
c) "list"
d) "collection"

Answer:

b) "object"

Explanation:

In JavaScript, arrays are technically a type of object, so the typeof operator returns "object" for an array.

14. How can you represent a date in JavaScript?

a) Using a string
b) Using a special Date object
c) Using a timestamp number
d) Using an array

Answer:

b) Using a special Date object

Explanation:

In JavaScript, dates are represented using the Date object, which can be created with a specific date string.

15. What type of data type is null in JavaScript?

a) Object
b) Undefined
c) Boolean
d) Number

Answer:

a) Object

Explanation:

In JavaScript, null is considered an object type, despite being used to represent the absence of any object value.

16. What value does JavaScript assign to a variable that is declared but not initialized?

a) 0
b) ""
c) null
d) undefined

Answer:

d) undefined

Explanation:

A variable that is declared but not initialized in JavaScript is automatically assigned the value undefined.

17. What is the result of using the typeof operator on the expression 3 + 4 in JavaScript?

a) "string"
b) "number"
c) "expression"
d) "integer"

Answer:

b) "number"

Explanation:

The typeof operator returns the type of the result of the expression, which in the case of 3 + 4 is a number.

18. Which statement is true regarding JavaScript types?

a) JavaScript types are static and cannot change once set.
b) JavaScript variables can hold multiple types at the same time.
c) JavaScript has dynamic types, meaning variables can hold different data types at different times.
d) JavaScript types are strictly enforced and cannot be automatically converted.

Answer:

c) JavaScript has dynamic types, meaning variables can hold different data types at different times.

Explanation:

JavaScript is a dynamically typed language, allowing variables to hold different data types at different times.

19. How does JavaScript interpret the addition of a number and a string?

a) As a mathematical addition operation
b) As a type conversion to number
c) As a syntax error
d) As a concatenation operation

Answer:

d) As a concatenation operation

Explanation:

When a number and a string are added in JavaScript, it treats the number as a string and performs concatenation.

20. What is the output of typeof new Date() in JavaScript?

a) "date"
b) "object"
c) "string"
d) "time"

Answer:

b) "object"

Explanation:

The new Date() in JavaScript creates a Date object, and therefore typeof new Date() returns "object".

Leave a Comment

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

Scroll to Top