JavaScript Datatypes and Variables
JavaScript Datatypes and Variables - Important Points
21. | What is the data type of a variable that stores an object in JavaScript? |
---|
A. Object
B. Array
C. Dictionary
D. Set
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The Object data type is used for storing objects in JavaScript.
22. | Which of the following is a valid way to declare a variable with constant block scope in JavaScript? |
---|
A. var myConst;
B. let myConst;
C. const myConst;
D. Only A and B
View Answer Discuss Work SpaceAnswer: option c
Explanation:
The const keyword can be used to declare a variable with constant block scope in JavaScript.
23. | Which of the following is not a valid way to declare and initialize an object in JavaScript? |
---|
A. var myObj = {};
B. let myObj = {key1: "value1", key2: "value2"};
C. const myObj = {key1: "value1", key2: "value2"};
D. myObj = {key1: "value1", key2: "value2"};
View Answer Discuss Work SpaceAnswer: option d
Explanation:
To declare and initialize an object in JavaScript, you need to use the var, let, or const keyword.
24. | Which of the following is a valid way to access a property of an object in JavaScript? |
---|
A. myObj.key;
B. myObj["key"];
C. Both A and B
D. None of the above
View Answer Discuss Work SpaceAnswer: option c
Explanation:
Both dot notation and bracket notation can be used to access a property of an object in JavaScript.
25. | Which of the following is not a valid JavaScript keyword? |
---|
A. let
B. const
C. var
D. int
View Answer Discuss Work SpaceAnswer: option d
Explanation:
int is not a valid JavaScript keyword.