167). The four kinds of class members are ________
[A]Instance methods, Instance fields, Static method, Dynamic method
[B]Instance fields, Instance methods, Class fields, Class methods
[C]Instance fields, Non-instance fields, Dynamic methods, Global methods
[D] Global methods, Local methods, Dynamic methods, Static methods
Show Answer
Correct Answer: Instance fields, Instance methods, Class fields, Class methods
Notes:
Answer: b
Explanation: A class mainly contains data members and associated member functions. Therefore over all different kinds of class members are instance field, instance method, class fields and class methods.
168). Different kinds of the object involved in a class definition are ________
[A]Public object, Private object, Protected object
[B] Constructor object, Function object, Destructor object
[C]Constructor object, Prototype object, Instance object
[D]Instance method, Static object, Dynamic object
Show Answer
Correct Answer: Constructor object, Prototype object, Instance object
Notes:
Answer: c
Explanation: In JavaScript, there are three different objects involved in any class definition, and the properties of these three objects act like different kinds of class members namely, Constructor object, Prototype object, and Instance object.
169). The object whose properties are inherited by all instances of the class, and properties whose values are functions behaving like instance methods of the class, is ________
[A] Instance object
[B]Constructor object
[C]Destructor object
[D]Prototype object
Show Answer
Correct Answer: Prototype object
Notes:
Answer: d
Explanation: The properties of the prototype object are inherited by all instances of the class, and properties whose values are functions behave like instance methods of the class.
170). Which variables are used internally in object methods and are also globally visible?
[A]Object properties
[B]Variable properties
[C]Method properties
[D]Internal properties
Show Answer
Correct Answer: Variable properties
Notes:
Answer: b
Explanation: The variable properties are usually variables that are used internally in the object’s methods, but can also be globally visible variables that are used through the page.
171). The class that represents the regular expressions is ________
[A]RegExpObj
[B]RegExpClass
[C]RegExp
[D]StringExp
Show Answer
Correct Answer: RegExp
Notes:
Answer: c
Explanation: Regular expression is an object that describes a pattern of characters. The JavaScript RegExp class represents regular expressions, and both string and RegExp define methods that use regular expressions.
172). The different variant of Date() constructor to create date object is/are ___________ i. new Date(date) ii. new Date(milliseconds) iii. new Date(date string) iv. new Date(year, month, date[hour, minute, second, millisecond])
[A]i, ii and iii only
[B]ii, iii and iv only
[C]i, ii and iv only
[D]i, ii, iii and iv
Show Answer
Correct Answer: ii, iii and iv only
Notes:
Answer: b
Explanation: Date() is a predefined object type in javascript. There are 4 ways to create a new date object:new Date(), new Date(year, month, day, hours, minutes, seconds, milliseconds), new Date(milliseconds), new Date(date string).
173). Which is the correct code that returns a complex number that is the complex conjugate of this one?
[A]Complex.prototype.conj = function() { return new Complex(this.r, -this.i); };
[B]Complex.prototype.conj = function() { return Complex(this.r, -this.i); };
[C]Complex.prototype.conj = function() { return (this.r, -this.i); };
[D]Complex.prototype.conj = function() { new Complex(this.r, -this.i); };
Show Answer
Correct Answer: Complex.prototype.conj = function() { return new Complex(this.r, -this.i); };
Notes:
Answer: a
Explanation: Object.prototype.constructor specifies the function that creates the object prototype. The above code snippet returns a complex number that is the complex conjugate of this one.
174). How can we make methods available on all objects?
[A]Object.add(methods)
[B]Object.methods(add)
[C]Object.add.methods(…)
[D] Object.prototype
Show Answer
Correct Answer: Object.prototype
Notes:
Answer: d
Explanation: It is possible to add methods to Object.prototype, making them available on all objects. This is not recommended, however, because prior to ECMAScript5, there is no way to make these add-on methods non enumerable, and if you add properties to Object.prototype, those properties will be reported by all for/in loops.
175). What is the procedure to add methods to HTMLElement so that they will be inherited by the objects that represent the HTML tags in the current document?
[A]HTMLElement.prototype(…)
[B]HTMLElement.prototype
[C] HTML.addmethods()
[D] HTML.elements(add)
Show Answer
Correct Answer: HTMLElement.prototype
Notes:
Answer: b
Explanation: It is implementation-dependent whether classes defined by the host environment (such as the web browser) can be augmented using Object.prototype. In many web browsers, for example, you can add methods to HTMLElement.prototype and those methods will be inherited by the objects that represent the HTML tags in the current document.
176). You can refresh the webpage in JavaScript by using ________
[A]window.reload
[B]location.reload
[C]window.refresh
[D]page.refresh
Show Answer
Correct Answer: location.reload
Notes:
Answer: b
Explanation: The reload method is used to reload the current file. User can reload the page from the server through location. Reload.
177). What will be the output of the following JavaScript code?
emp={id:102,name:"Shyam Kumar",salary:40000}
document.write(emp.id+" "+emp.name+" "+emp.salary);
[A]102 4000 Shyam Kumar
[B]102 4000
[C] 102 Shyam Kumar 40000
[D]102 shyam kumar 40000
Show Answer
Correct Answer: 102 4000
Notes:
Answer: b
Explanation: In this method, the object is created using literals. Property and Value are separated by colon.
178). What will be the output of the following JavaScript code?
function emp(id,name)
{
this.id=id;
this.name=name;
}
e=new emp(103,"Vimal Jaiswal");
document.write(e.id+" "+e.name");
[A]103 vimal jaiswal
[B]103
[C]103 Vimal Jaiswal
[D]Vimal jaiswal
Show Answer
Correct Answer: 103 Vimal Jaiswal
Notes:
Answer: c
Explanation: Object in the above code is created by passing arguments to the function. “this” keyword is used for defining the values.
179). What will be the output of the following JavaScript code?
var emp=new Object();
emp.name="Ravi Malik";
emp.salary=50000;
document.write("emp.name+" "+emp.salary);
[A]Ravi malik 5000
[B]Ravi Malik 50000
[C]Ravi malik
[D]50000
Show Answer
Correct Answer: Ravi Malik 50000
Notes:
Answer: b
Explanation: In the above code an object of class emp is made using the new operator. The above code prints the value of name and salary as defined in the object of the class.
180). What will be the output of the following JavaScript code?
function emp(name,salary)
{
this.name=name;
this.salary=salary;
this.changeSalary=changeSalary;
function changeSalary(otherSalary)
{
this.salary=otherSalary;
}
}
e=new emp("Rahul",30000);
e.changeSalary(45000);
document.write("e.name+" "+e.salary);
[A]Rahul 30000
[B]Rahul
[C]Rahul 45000
[D]45000
Show Answer
Correct Answer: Rahul 45000
Notes:
Answer: c
Explanation: The above code defines an additional method in JavaScript object. But before defining method, the property should be added in the function with the same name as method.
181). What will be the output of the following JavaScript code?
const obj = { 10: 'arry', 21: 'barry', 23: 'carry' };
console.log(Object.entries(obj)[2]);
[A][“arry”, “10”]
[B] [“10”,”arry”]
[C][“21”,barry”]
[D] [“23”,”carry”]
Show Answer
Correct Answer: [“23”,”carry”]
Notes:
Answer: d
Explanation: Object.entries() method is used to return an array of a given object’s own [key, value] pairs. The ordering of the properties is the same as that given by looping over the property values of the object manually.