This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Object Attributes and Serialization”.
1. The unordered collection of properties, each of which has a name and a value is called _________
a) String
b) Object
c) Serialized Object
d) Array
View Answer
Explanation: Objects in JavaScript may be defined as an unordered collection of related data, of primitive or reference types, in the form of “key:value” pairs. Hence each of the property has a name and value.
2. The object has three object attributes namely ________
a) Class, parameters, object’s extensible flag
b) Prototype, class, objects’ parameters
c) Prototype, class, object’s extensible flag
d) Native object, Classes and Interfaces and Object’s extensible flag
View Answer
Explanation: Every object has three associated object attributes:
- An object’s prototype is a reference to another object from which properties are inherited.
- An object’s class is a string that categorizes the type of an object.
- An object’s extensible flag specifies whether new properties may be added to the object.
3. What will be the firstname and surname of the following JavaScript code?
var book = { "main title": "JavaScript", 'sub-title': "The Definitive Guide", "for": "all audiences", author: { firstname: "David", surname: "Flanagan" } };
a) properties
b) property values
c) property names
d) objects
View Answer
Explanation: The above code snippet contains an object inside another object. firstname and surname are the property names. The value of that particular property is itself an object.
4. A linkage of series of prototype objects is called as ________
a) prototype stack
b) prototype chain
c) prototype class
d) prototypes
View Answer
Explanation: Consider an example, Date.prototype inherits properties from Object.prototype, so a Date object created by new Date() inherits properties from both Date.prototype and Object.prototype. This linked series of prototype objects is known as prototype chain.
5. In the following syntax, the data type within the square brackets must be ___________
book[datatype]=assignment_value;
a) An integer
b) A String
c) An object
d) Floating point
View Answer
Explanation: The value inside the square bracket is used to access that data element or the property of the object. When using square bracket notation, the expression inside the square brackets must evaluate to a string or a value that can be converted to a string.
6. To determine whether one object is the prototype of (or is part of the prototype chain of) another object, one should use the ____________
a) isPrototypeOf() method
b) equals() method
c) === operator
d) ==opertor
View Answer
Explanation: Prototype is a global property which is available with almost all the objects. To determine whether one object is the prototype of (or is part of the prototype chain of) another object, one should use the isPrototype() method. To find out if p is the prototype of o write p.isPrototypeOf(o).
7. What is the prototype represents in the following JavaScript code snippet?
function f() {};
a) Function f
b) A custom constructor
c) Prototype of a function
d) Not valid
View Answer
Explanation: All object instances have a constructor property that point to the constructor function that created it. A custom constructor is a constructor which requires no arguments and is created automatically by the compiler at the time of object creation if not created by the user.
8. The purpose of extensible attribute is to __________
a) make all of the own properties of that object non configurable
b) to configure and bring a writable property
c) “lock down” objects into a known state and prevent outside tampering
d) to include new properties into the object
View Answer
Explanation: Extensible attributes determines whether the object can have new properties or not. Therefore extensible attribute will allow an object to include and write properties into them.
9. Identify the process done in the following JavaScript code snippet?
o = {x:1, y:{z:[false,null,""]}}; s = JSON.stringify(o); p = JSON.parse(s);
a) Object Encapsulation
b) Object Serialization
c) Object Abstraction
d) Object Encoding
View Answer
Explanation: Object serialization is the process of converting an object’s state to a string from which it can later be restored. The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string.
10. The basic purpose of the toLocaleString() is to _________
a) return a localised object representation
b) return a parsed string
c) return a local time in the string format
d) return a localized string representation of the object
View Answer
Explanation: .toLocaleString is a predefined function in javascript which is used to return a localized string representation of the object. For example the date.toLocaleString() is an inbuilt function in JavaScript which is used to convert a date and time to a string.
11. What will be the output of the following JavaScript code?
const object1 = {}; a = Symbol('a'); b = Symbol.for('b'); object1[a] = 'harry'; object1[b] = 'derry'; const objectSymbols = Object.getOwnPropertySymbols(object1); console.log(objectSymbols.length);
a) 0
b) 2
c) 1
d) Error
View Answer
Explanation: The Object.getOwnPropertySymbols() method returns an array of all symbol properties found directly on an object. This method returns an empty array unless you have set symbol properties on your object.
12. What will be the output of the following JavaScript code?
const obj1 = { property1: 21 } const descriptor1 = Object.getOwnPropertyDescriptor(obj1, 'property1'); console.log(descriptor1.configurable); console.log(descriptor1.enumerable);
a) true 21
b) true false
c) true true
d) false false
View Answer
Explanation: The Object.getOwnPropertyDescriptor method allows to query the full information about a property. The method returns a property descriptor for an own property that is one directly present on an object and not in the object’s prototype of a given object.
13. What will be the output of the following JavaScript code?
const obj1 = { property1: '10'}; const obj2 = Object.freeze(obj1); obj2.property1 = '20'; console.log(obj2.property1);
a) 10
b) 20
c) Runtime error
d) Compilation error
View Answer
Explanation: The Object.freeze() method “freezes” the properties of object and prevents new properties from being added to it. This method prevents the modification of existing property, attributes, and values.
14. What will be the output of the following JavaScript code?
const object1 = { property1: 20 }; console.log(Object.is(object1));
a) 20
b) true
c) false
d) error
View Answer
Explanation: The Object.is() method of JavaScript is used to determine whether two values are the same value. There is a special built-in method that compares values. This method returns a Boolean indicating whether or not the two arguments are the same value.
15. What will be the output of the following JavaScript code?
const obj = {prop: 12}; Object.preventExtensions(obj); console.log( Object.isExtensible(obj));
a) 12
b) false
c) true
d) error
View Answer
Explanation: The Object.preventExtensions() only prevents the addition of new properties from ever being added to an object. This change is a permanent that means once an object has been made non-extensible, it cannot be made extensible again.
Sanfoundry Global Education & Learning Series – Javascript Programming.
- Practice MCA MCQs
- Practice Information Science MCQs
- Practice Programming MCQs
- Check JavaScript Books
- Check Programming Books