JavaScript Datatypes and Variables
JavaScript Datatypes and Variables - Important Points
1. | What is the data type of a variable that stores a whole number in JavaScript? |
---|
A. Number
B. String
C. Boolean
D. Object
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The Number data type is used for storing numeric values in JavaScript.
2. | Which of the following is not a valid data type in JavaScript? |
---|
A. Undefined
B. Null
C. NaN
D. Char
View Answer Discuss Work SpaceAnswer: option d
Explanation:
Char is not a valid data type in JavaScript. The other three are valid data types.
3. | Which of the following is a valid way to declare a variable in JavaScript? |
---|
A. var myVar = 1;
B. let myVar = 1;
C. const myVar = 1;
D. All of the above
View Answer Discuss Work SpaceAnswer: option d
Explanation:
All three ways of declaring a variable are valid in JavaScript.
4. | What is the value of a variable that has been declared but not initialized in JavaScript? |
---|
A. undefined
B. null
C. NaN
D. 0
View Answer Discuss Work SpaceAnswer: option a
Explanation:
If a variable has been declared but not initialized, its value is undefined.
5. | Which of the following is a valid way to check the data type of a variable in JavaScript? |
---|
A. typeof myVar;
B. myVar.type();
C. myVar.getType();
D. typeOf(myVar);
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The typeof operator can be used to check the data type of a variable in JavaScript.