1. What are the basic data types in JavaScript?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
Explanation:
An empty string in JavaScript is still of type "string".
8. What are the possible values of a Boolean type in JavaScript?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
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?
Answer:
Explanation:
The new Date() in JavaScript creates a Date object, and therefore typeof new Date() returns "object".