Javascript (JS) Object MCQ
This section focuses on the "Javascript Object" of the Javascript. These Multiple Choice Questions (mcq) should be practiced to improve the Javascript skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. What will be printed in the console on execution of the following JS code:
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
var myArr= array.filter(v => v % 3 === 0);
console.log(myArr);
A. myArr
B. [3, 6, 9, 12, 15]
C. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
D. [1, 2, 4, 5, 7, 8, 10, 11, 13, 14]
View Answer
Ans : B
Explanation: This option is correct because, filter function will iterate through the array and will create an array of values if the condition is true. Hence all the elements divisible by three will be printed.
2. What will be printed in the console on execution of the following JS code:
var array = [2, 4, 6, 7, 8, 10];
var myArr= array.filter(v => v / 2 === 0);
console.log(myArr);
A. myArr
B. [2, 4, 6, 7, 8, 10]
C. [2, 4, 6, 8, 10]
D. [7]
View Answer
Ans : C
Explanation: This option is correct because, filter function will iterate through the array and will create an array of values if the condition is true. Hence all the elements divisible by two will be printed.
3. What will be printed in the console on execution of the below code?
var materials = [
'Hydrogen',
'Helium',
'Lithium',
'Beryllium'
];
console.log(materials.map (material => material.length));
A. [8, 6, 7, 9]
B. 4
C. [4]
D. 8, 6, 7, 9
View Answer
Ans : A
Explanation: This option is correct because, map function will create a new array having length of each material in the array.
4. What will be printed in the console on execution of the below code?
var materials = [
'Table',
'Chair',
'Boxes',
'Press'
];
console.log(materials.map (material => material.length));
A. [5,5,5,5]
B. [5]{4}
C. [5]
D. Both A and B
View Answer
Ans : A
Explanation: This option is correct because, map function will create a new array having length of each material in the array.
5. what will be the output of below code?
var val = "JavaScript String"
splittedVal = val.split('a',2)
console.log(splittedVal);
A. [ 'J', 'v' ]
B. [ 'J' ,'v','Script']
C. [ 'J', 'v', 'Script String' ]
D. [ 'JavaScript String' ]
View Answer
Ans : A
Explanation: This option is correct because, split method will split a string into substrings using the specified separator and return them as an array.
6. what will be the output of below code?
NOTE: The code is executed on 2019-5-9
var todaysDate = new Date()
console.log( todaysDate.toLocaleString() );
A. 2019-05-09T09:29:53.181Z
B. 2019-5-9
C. 15:00:34
D. 2019-5-9 15:02:35
View Answer
Ans : D
Explanation: This option is correct because, toLocaleString() will convert a date and time to a string by using the current or specified locale.
7. ........ serializes only the enumerable own properties of an object.
A. JSON.Parse()
B. JSON.Stringify()
C. JSON.Null()
D. JSON.Objectify()
View Answer
Ans : B
Explanation: JSON.Stringify() serializes only the enumerable own properties of an object.
8. Object ......... is the process of converting an objects state to a string from which it can later be restored.
A. prototype
B. class
C. serialization
D. extensible
View Answer
Ans : C
Explanation: Object serialization is the process of converting an object's state to a string from which it can later be restored.
9. If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the paragraph?
A. "New Text"?
B. para1.value="New Text";
C. para1.firstChild.nodeValue= "New Text";
D. para1.nodeValue="New Text";
View Answer
Ans : B
Explanation: para1.value="New Text"; is the correct syntax to change the text within the paragraph.
10. what will be the output of below code?
const event = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
console.log (event.toLocaleString('en-IN', { timeZone: 'UTC' }));
A. 20/12/2012, 3:00:00
B. 12/20/2012, 3:00:00
C. 20/12/2012, 3:00:00 am
D. 2012/12/20, 3:00:00 am
View Answer
Ans : C
Explanation: 20/12/2012, 3:00:00 am will be the output of below code.
11. A programming language can be called object-oriented if it provides ________ basic capabilities to developers
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : D
Explanation: A programming language can be called object-oriented if it provides four basic capabilities to developers : Encapsulation, Aggregation, Inheritance and Polymorphism
12. The capability to store one object inside another object known as?
A. Encapsulation
B. Aggregation
C. Inheritance
D. Polymorphism
View Answer
Ans : B
Explanation: Aggregation : the capability to store one object inside another object.
13. The syntax for adding a property to an object is?
A. objectProperty == propertyValue;
B. objectProperty = propertyValue;
C. objectName.objectProperty = propertyValue;
D. objectName.objectProperty == propertyValue;
View Answer
Ans : C
Explanation: The syntax for adding a property to an object is : objectName.objectProperty = propertyValue;
14. The ________ operator is used to create an instance of an object.
A. this
B. self
C. find
D. new
View Answer
Ans : D
Explanation: The new operator is used to create an instance of an object. To create an object, the new operator is followed by the constructor method.
15. JavaScript provides a special constructor function called Object() to build the object.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: True, JavaScript provides a special constructor function called Object() to build the object.
Also check :
Discussion