JavaScript Questions & Answers – Object Attributes and Serialization | JavaScript MCQs
Questions
1
The unordered collection of properties, each of which has a name and a value is called _________
Answer: Object
2
The object has three object attributes namely ________
Answer: Prototype, class, object’s extensible flag
⭐ Make GKSeries Your Preferred Source on Google
Add GKSeries as Preferred Source
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"
}
};
Answer: property names
4
A linkage of series of prototype objects is called as ________
Answer: prototype chain
5
In the following syntax, the data type within the square brackets must be ___________
book[datatype]=assignment_value;
Answer: 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 ____________
Answer: isPrototypeOf() method
7
What is the prototype represents in the following JavaScript code snippet?
function f() {};
Answer: A custom constructor
8
The purpose of extensible attribute is to __________
Answer: “lock down” objects into a known state and prevent outside tampering
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);
Answer: Object Serialization
10
The basic purpose of the toLocaleString() is to _________
Answer: return a localized string representation of the object
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);
Answer: 2
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);
Answer: true true
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);
Answer: 10
14
What will be the output of the following JavaScript code?
const object1 = {
property1: 20
};
console.log(Object.is(object1));
Answer: false
15
What will be the output of the following JavaScript code?
const obj = {prop: 12};
Object.preventExtensions(obj);
console.log( Object.isExtensible(obj));
Answer: false