JavaScript Datatypes and Variables
JavaScript Datatypes and Variables - Important Points
| 16. | Which of the following is a valid way to declare a variable with block scope in JavaScript? |
|---|
A. var myVar;
B. let myVar;
C. const myVar;
D. Only A and C
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The let keyword can be used to declare a variable with block scope in JavaScript.
| 17. | What is the data type of a variable that stores a date and time value in JavaScript? |
|---|
A. Date
B. Time
C. DateTime
D. Moment
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The Date data type is used for storing date and time values in JavaScript.
| 18. | Which of the following is not a valid way to declare and initialize a variable in JavaScript? |
|---|
A. var myVar = 1;
B. myVar = 1;
C. let myVar = 1;
D. const myVar = 1;
View Answer Discuss Work SpaceAnswer: option b
Explanation:
To declare and initialize a variable in JavaScript, you need to use the var, let, or const keyword.
| 19. | Which of the following is a valid way to declare an empty array in JavaScript? |
|---|
A. var myArr = [];
B. let myArr = {};
C. const myArr = ();
D. All of the above
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The [] syntax is used to declare an empty array in JavaScript.
| 20. | Which of the following is a valid way to concatenate two strings in JavaScript? |
|---|
A. Hello + "world";
B. Hello.concat("world");
C. Both A and B
D. None of the above
View Answer Discuss Work SpaceAnswer: option c
Explanation:
Both the + operator and the concat() method can be used to concatenate strings in JavaScript.