Javascript (JS) Custom Objects MCQ

This section focuses on the "Javascript Custom Objects" 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 the output of the below code?
class Rect {
constructor(h, w) {
this.height = h;
this.width = w;
}
get foo() {
return this.foo();
}
foo() {
return this.height * this.width;
}
}

const sq = new Rect(5, 20);
console.log(sq.foo());

A. this.height * this.width
B. 100
C. Reference Error
D. 5*20

View Answer


2. Choose the correct syntax in order to access property of the object created?
function Ticket(from,to,pName){
this.from=from;
this.to=to;
this.pName= pName;
}

var ticket=new Ticket( "Udaipur","Pune","Raj" );

A. ticket.from & ticket[to]
B. ticket[to] & ticket[from]
C. ticket {to} & ticket.to
D. ticket[to] & ticket{from}

View Answer


3. Identify the correct syntax to create a JavaScript object for Employee with property empid, empName?
function Ticket(from,to,pName){
this.from=from;
this.to=to;
this.pName= pName;
}

var ticket=new Ticket( "Udaipur","Pune","Raj" );

A. var employee=new Object(); employee.empid=20; employee.empName="John";
B. var employee ={id:2001,empName:"John"};
C. var employee=Employee(); employee.empid=20; employee.empName="John";
D. Both A and C

View Answer


4. Consider the below code:
Choose the appropriate statement to be inserted at line 2, in order to create a JavaScript object named student?
var json= '{ "sId":2001,"sName":"John" }';
//line 2
console.log(student.sId+" "+student.sName);

A. var student=json.parse(json);
B. var student=JSON.stringify(json);
C. var student=JSON.parse(json);
D. var student=json.stringify(json);

View Answer


5. What will be the output of the following JavaScript code?
var obj = new Fun(); obj.constructor === Fun

A. true
B. false
C. 0
D. 1

View Answer


6. If X is the superclass and Y is the subclass, then subclass inheriting the superclass can be represented as _________

A. Y=inherit(X);
B. Y=X.inherit();
C. Y.prototype=inherit(X);
D. Y.prototype=inherit(X.prototype);

View Answer


7. What will be the output of the following JavaScript code?
const ob1 = { a: 5, b: 10, c: 15 }; const ob2 = Object.assign({c: 8, d: 3}, ob1); console.log(ob2.c, ob2.d);

A. 8,3
B. 15,3
C. undefined
D. error

View Answer


8. What will be the output of the following JavaScript code?
const pt1 = {};
const ob1 = Object.create(pt1);
console.log( Object.getPrototypeOf(ob1) === pt1 );

A. true
B. false
C. errot
D. 0

View Answer


9. A linkage of series of prototype objects is called as :

A. prototype stack
B. prototype chain
C. prototype class
D. prototypes

View Answer


10. Which is an equivalent code to invoke a function m of class o that expects two arguments x and y?

A. o(x,y);
B. o.m(x) && o.m(y);
C. m(x,y);
D. o.m(x,y);

View Answer






Also check :


Discussion



* You must be logged in to add comment.