Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Which of the following is an example to perform the most common XML manipulations using the XML objects invocation?(a) insertChildBefore()(b) insertChildAfter()(c) appendChildAfter(…)(d) appendChildBefore(…)I got this question during an internship interview.This intriguing question comes from Shorthand functions and Multiple catch clauses in section Classes and Modules in JavaScript of JavaScript

Answer» RIGHT CHOICE is (a) insertChildBefore()

EASIEST EXPLANATION: E4X is designed so that you can perform most common XML manipulations using language syntax. E4X also defines methods you can invoke on XML OBJECTS. Here, for example, is the insertChildBefore() method:
2.

Which method to use while working with XML fragments, instead of XML()?(a) XMLInterface()(b) XMLClass()(c) XMLList()(d) XMLArray()I got this question at a job interview.My doubt is from Shorthand functions and Multiple catch clauses in portion Classes and Modules in JavaScript of JavaScript

Answer»

The correct answer is (C) XMLLIST()

For EXPLANATION: An XML fragment is an XML DOCUMENT with no single top-level root ELEMENT. When working with XML fragments, use XMLList() instead of XML().

3.

Which of the following is the descendant operator?(a) ..(b) …(c) *(d) @I had been asked this question in an online quiz.I'm obligated to ask this question of Shorthand functions and Multiple catch clauses in portion Classes and Modules in JavaScript of JavaScript

Answer»

The correct option is (a) ..

Easy explanation: While the . OPERATOR ACCESSES direct children of the given node, the .. operator accesses all children no matter how DEEPLY nested: The .. operator is the DESCENDANT operator; you can use it in place of the normal. member-access operator:

4.

When will the finally block be called?(a) When there is no exception(b) When the catch does not match(c) When there is exception(d) After try-catch executionI have been asked this question in an interview.Asked question is from Shorthand functions and Multiple catch clauses topic in section Classes and Modules in JavaScript of JavaScript

Answer»

Correct answer is (d) After try-catch execution

To explain: The try and catch STATEMENT HANDLES some or all of the errors that may occur in a block of code, while STILL RUNNING code. A finally block is CALLED after try-catch execution.

5.

What will be the reaction when a catch clause has no conditionals?(a) Takes it to be 0(b) Takes it to be 1(c) Takes it to be true(d) Takes it to be falseThe question was asked by my school teacher while I was bunking the class.My question is based upon Shorthand functions and Multiple catch clauses in chapter Classes and Modules in JavaScript of JavaScript

Answer»

Correct option is (C) Takes it to be TRUE

The explanation: The try and catch statement handles some or all of the errors that may occur in a block of code, while STILL running code. If a catch clause has no conditional, it BEHAVES as if it has the conditional if true, and it is always triggered if no clause before it was triggered.

6.

What is the return type of typeof for standard JavaScript objects?(a) xml(b) object(c) dom(d) htmlI got this question during an interview.Question is taken from Shorthand functions and Multiple catch clauses topic in section Classes and Modules in JavaScript of JavaScript

Answer»

Right option is (b) object

To explain I would say: The TYPEOF operator returns “object” for all standard JAVASCRIPT OBJECTS. It returns “object” for a null, “number” for NaN, “number” for Infinity, “object” for a “new Number(1)” and “object” for an array.

7.

Which exception does the Iterators throw from their next() method when there are no more values to iterate, that work on finite collections?(a) Exit Iteration(b) Abort Iteration(c) Abort(d) Stop IterationThe question was posed to me during an internship interview.This interesting question is from JavaScript Extensions in section Classes and Modules in JavaScript of JavaScript

Answer»

The correct answer is (d) Stop ITERATION

The best explanation: Iterators that work on finite COLLECTIONS throw Stop Iteration from their next() method when there are no more values to iterate. Stop Iteration is a property of the global object in JavaScript 1.7. Its value is an ordinary object (with no PROPERTIES of its own) that is reserved for this special purpose of TERMINATING iterations. Note, in PARTICULAR,that Stop Iteration is not a constructor function like TypeError() or RangeError().

8.

What is the code to be used to trim whitespaces?(a) let trimmed = (l.trim() for (l in lines));(b) let trimmed = (trim(l));(c) let trimmed = l.trim();(d) let trimmed = for(l in lines));This question was addressed to me in an interview for job.Query is from Shorthand functions and Multiple catch clauses topic in section Classes and Modules in JavaScript of JavaScript

Answer»

The correct OPTION is (a) let trimmed = (l.TRIM() for (l in lines));

Best EXPLANATION: The various types of trim functions are trimLeft(), trimRight() and trim().can use the above code to trim whitespaces and FILTER out comments and blank lines.

9.

Which looping statement allows XML tags to appear in JavaScript programs and adds API for operating on XML data?(a) for loop(b) while loop(c) for/each loop(d) do while loopThis question was posed to me in an international level competition.My query is from JavaScript Extensions topic in section Classes and Modules in JavaScript of JavaScript

Answer»

The correct answer is (c) for/each loop

Easy explanation: The for/each loop is a NEW LOOPING statement STANDARDIZED by E4X. E4X (ECMASCRIPT for XML) is a language extension that allows XML tags to appear literally in JavaScript programs and adds syntax and API for OPERATING on XML data.

10.

The main difference between the variables declared with var and with let is __________(a) var is confined to a particular function but let is not(b) let is confined to a particular function but var is not(c) var defines values based on conditions but let does not(d) let doesn’t let you change the value of the variableI had been asked this question in my homework.My query is from JavaScript Extensions topic in portion Classes and Modules in JavaScript of JavaScript

Answer»

Right choice is (b) let is CONFINED to a particular function but var is not

Best explanation: Variables declared with var have global scope whereas VARIABLE declared with let have BLOCK scope. Variables declared with let are DEFINED only within the CLOSEST enclosing block (and any blocks nested within it, of course).

11.

The let keyword cannot be used ___________(a) as a substitute of var(b) as a block statement to define new variables(c) to define variables that are scoped to a single expression(d) in a else if loop, as a substitute for varI have been asked this question in an interview for job.My enquiry is from JavaScript Extensions topic in division Classes and Modules in JavaScript of JavaScript

Answer»

Right option is (d) in a else if LOOP, as a substitute for var

The explanation is: The LET keyword can be used in FOUR ways :

as a VARIABLE declaration like var;

in a for or for/in loop, as a substitute for var;

as a block statement, to define new variables and explicitly delimit their scope; and

to define variables that are scoped to a single EXPRESSION.

12.

Which was one of the first security subsets proposed?(a) FBJS(b) Caja(c) dojox.secure(d) ADSafeThis question was addressed to me in my homework.My question is taken from JavaScript Subsets topic in portion Classes and Modules in JavaScript of JavaScript

Answer»

Correct option is (d) ADSafe

The explanation is: ADsafe was one of the FIRST security SUBSETS PROPOSED) It was created by Douglas Crockford (who also defined The Good Parts subset). ADsafe relies on static verification only, and it uses JSLint as its verifier. It forbids access to most GLOBAL variables and defines an ADSAFE variable that provides access to a secure API, including special-purpose DOM methods. ADsafe is not in WIDE use, but it was an influential proof-of-concept that influenced other secure subsets.

13.

Which is the object that defines methods that allow complete control over page content?(a) The client-side document object(b) The server-side document object(c) Both client-side and server-side document object(d) Web document objectThis question was posed to me during an online exam.The question is from JavaScript Subsets in chapter Classes and Modules in JavaScript of JavaScript

Answer» RIGHT choice is (a) The client-side document OBJECT

Explanation: A web page is divided into two object documents in which ONE is client-side document object and the other is server-side document object. The client-side document object defines methods that allow COMPLETE control over page content
14.

Which are the two functions that are not allowed in any secure subset?(a) evaluate() and restrict()(b) eval() and the Function() constructor(c) debugger() and test()(d) eval() and debugger()I had been asked this question in homework.Question is taken from JavaScript Subsets in chapter Classes and Modules in JavaScript of JavaScript

Answer»

Right answer is (b) eval() and the FUNCTION() constructor

To explain: eval() and the Function() constructor are not ALLOWED in any SECURE subset because they allow the execution of arbitrary strings of code, and these strings cannot be STATICALLY ANALYZED.

15.

Why was “The Good Parts” designed as a language subset in JavaScript?(a) To improve programmer flexibility(b) To balance the workload of the programmer(c) To create an in-built compiler and interpreter(d) To improve programmer productivityI got this question in examination.My enquiry is from JavaScript Subsets in portion Classes and Modules in JavaScript of JavaScript

Answer»

The correct CHOICE is (d) To improve programmer productivity

To explain I would say: The Good Parts is a language subset designed for aesthetic reasons and with a desire to improve programmer productivity. There is a larger class of subsets that have been designed for the purpose of SAFELY running UNTRUSTED JavaScript in a secure container or “SANDBOX”.

16.

Why is this keyword not preferred in JavaScript?(a) Highly memory consuming(b) Functions should access the global objects(c) Functions should not access the global objects(d) Very inefficient to useThis question was posed to me in quiz.I need to ask this question from JavaScript Subsets in portion Classes and Modules in JavaScript of JavaScript

Answer» CORRECT answer is (c) FUNCTIONS should not access the global objects

For explanation I WOULD say: The this keyword is forbidden or RESTRICTED because functions (in non-strict mode) can access the global object through this. Preventing access to the global object is ONE of the key purposes of any sandboxing system.
17.

Which is the subset that is a secure container designed for the purpose of safely running untrusted JavaScript?(a) Sandbox(b) The Good Parts(c) Both Sandbox and Good Parts(d) Web browserThe question was asked during an interview for a job.My question is from JavaScript Subsets topic in division Classes and Modules in JavaScript of JavaScript

Answer»

Correct choice is (a) SANDBOX

Easy EXPLANATION: There is a larger class of SUBSETS that have been designed for the purpose of safely RUNNING untrusted JavaScript in a secure container or “sandbox”.

18.

What is being imposed on each subset to ensure that it conforms to the subset?(a) A parser to parse the code(b) A parser that parses and adds to the subset(c) A static verifier that parses code(d) A predefined function to parse the codeThe question was posed to me at a job interview.Origin of the question is JavaScript Subsets in portion Classes and Modules in JavaScript of JavaScript

Answer»

Right OPTION is (c) A static verifier that parses code

Best explanation: Each SUBSET is COUPLED with a static verifier that parses code to ENSURE that it CONFORMS to the subset.

19.

What does javascript use instead of == and !=?(a) It uses bitwise checking(b) It uses === and !== instead(c) It uses equals() and notequals() instead(d) It uses equalto()The question was posed to me during an interview for a job.This intriguing question comes from JavaScript Subsets topic in chapter Classes and Modules in JavaScript of JavaScript

Answer» RIGHT ANSWER is (b) It uses === and !== instead

Best EXPLANATION: The subset does not include the comma operator, the bitwise operators, or the ++ and — operators. It also disallows == and != because of the TYPE conversion they perform, requiring USE of === and !== instead.
20.

The Crockford’s subset does not include which function in JavaScript?(a) eval()(b) coeval()(c) equal()(d) equivalent()I had been asked this question during an interview.My doubt stems from JavaScript Subsets in chapter Classes and Modules in JavaScript of JavaScript

Answer» CORRECT OPTION is (a) eval()

EXPLANATION: The Crockford’s subset does not INCLUDE the with and continue statements or the eval() FUNCTION. It defines functions using function definition expressions only and does not include the function definition statement.
21.

The method that performs the search-and-replace operation to strings for pattern matching is _______(a) searchandreplace()(b) add()(c) edit()(d) replace()This question was addressed to me during an internship interview.My doubt is from Pattern Matching and Regular Expressions topic in portion Classes and Modules in JavaScript of JavaScript

Answer»

Correct CHOICE is (d) replace()

The best I can explain: The replace() method PERFORMS a search-and-replace operation. It takes a REGULAR EXPRESSION as its first argument and a replacement STRING as its second argument.

22.

What is the most essential purpose of parentheses in regular expressions?(a) Define pattern matching techniques(b) Define subpatterns within the complete pattern(c) Define portion of strings in the regular expression(d) matching the complete stringThis question was addressed to me during an interview.I want to ask this question from Pattern Matching and Regular Expressions topic in portion Classes and Modules in JavaScript of JavaScript

Answer»

The correct option is (b) Define subpatterns within the COMPLETE pattern

The BEST explanation: When a REGULAR expression is successfully matched against a target STRING, it is possible to extract the portions of the target string that matched any particular paranthesized subpattern. The essential PURPOSE of parantheses in regular expressions is to define subpatterns within the complete pattern.

23.

What does the subexpression /java(script)?/ result in?(a) It matches “java” followed by the optional “script”(b) It matches “java” followed by any number of “script”(c) It matches “java” followed by a minimum of one “script”(d) It matches “java” followed by a single “script”I have been asked this question during an online exam.This interesting question is from Pattern Matching and Regular Expressions topic in portion Classes and Modules in JavaScript of JavaScript

Answer»

Right CHOICE is (a) It matches “java” followed by the optional “SCRIPT

For explanation: PARANTHESIS () CHECK for the optional presence of the argument in the STRING. subexpression /java(script)?/ matches “java” followed by the optional “script”.

24.

What will be the result when non greedy repetition is used on the pattern /a+?b/?(a) Matches the letter b preceded by the fewest number of a’s possible(b) Matches the letter b preceded by any number of a(c) Matches letter a preceded by letter b, in the stack order(d) Matches letter a present in the stringI got this question in an interview.The question is from Pattern Matching and Regular Expressions in portion Classes and Modules in JavaScript of JavaScript

Answer»

The correct option is (a) Matches the LETTER b preceded by the fewest number of a’s possible

The best explanation: Using NON greedy repetition may not always produce the RESULTS you expect. /a+?b/ matches the letter b preceded by the fewest number of a’s possible.

25.

What does /[^(]* regular expression indicate?(a) Match one or more characters that are not open parenthesis(b) Match zero or more characters that are open parenthesis(c) Match zero or more characters that are not open parenthesis(d) Match one or more characters that are open parenthesisThis question was addressed to me in final exam.This intriguing question comes from Pattern Matching and Regular Expressions in division Classes and Modules in JavaScript of JavaScript

Answer»

Correct choice is (c) Match zero or more characters that are not OPEN parenthesis

To EXPLAIN I would SAY: The [^…] character class is used to match or draw any one character not between the brackets. One should always be careful while using * and ? as REPETITION characters as they may match zero INSTANCES of whatever precedes them, they are allowed to match nothing.

26.

The regular expression to match any one character not between the brackets is __________(a) […](b) [^](c) [^…](d) [\D]This question was addressed to me during an online interview.This interesting question is from Pattern Matching and Regular Expressions topic in portion Classes and Modules in JavaScript of JavaScript

Answer»

The correct ANSWER is (C) [^…]

For explanation I would SAY: RegExp DEFINES a special set of character that is used to do MANIPULATION on strings and other variables. The [^…] character class is used to match or draw any one character not between the brackets.

27.

The provides() function and the exportsobject are used to _________(a) Register the module’s API and Store their API(b) Call the modules api(c) Store the module’s API(d) Register the modules apiThe question was asked by my school principal while I was bunking the class.My question is from Modules in JavaScript topic in division Classes and Modules in JavaScript of JavaScript

Answer»

Correct choice is (a) Register the MODULE’s API and Store their API

Explanation: FRAMEWORKS that DEFINE module loading systems MAY have other methods of exporting a module’s API. There may be a provides() function for MODULES to register their API, or an exports object into which modules must store their API.

28.

The ‘$’ present in the RegExp object is called a ____________(a) character(b) matcher(c) metacharacter(d) metadataI had been asked this question by my school teacher while I was bunking the class.I want to ask this question from Pattern Matching and Regular Expressions in chapter Classes and Modules in JavaScript of JavaScript

Answer»

The correct answer is (C) metacharacter

Easiest explanation: The ‘S’ is a special metacharacter that MATCHES the end of a STRING. It is used to define or access ELEMENTS in jquery.

29.

The properties() method is a ________(a) Enumerable method(b) Non-enumerable method(c) Operational method(d) calling methodThe question was asked in my homework.The question is from Modules in JavaScript in chapter Classes and Modules in JavaScript of JavaScript

Answer»

The correct answer is (b) Non-enumerable method

To explain: The PROPERTIES() is a method to get INFORMATION of the properties of a PARTICULAR object. properties() method is a non-enumerable method.

30.

Modules that have more than one item in their API can ________(a) Assign itself to a global variable(b) Invoke another module of the same kind(c) Return a namespace object(d) Invoke another module of the same kindThis question was addressed to me by my college director while I was bunking the class.Origin of the question is Modules in JavaScript in division Classes and Modules in JavaScript of JavaScript

Answer»

The correct answer is (c) RETURN a namespace object

The explanation is: Namespace is a container for a set of identifiers, FUNCTIONS, methods and all that. It GIVES a level of DIRECTION to its contents so that it will be well distinguished and organized. Modules that have more than one item in their API can return a namespace object.

31.

The scope of a function is also called as ________(a) Predefined function(b) Module function(c) Public function(d) Private functionThe question was posed to me by my college professor while I was bunking the class.Asked question is from Modules in JavaScript in chapter Classes and Modules in JavaScript of JavaScript

Answer»

Correct answer is (b) MODULE function

To ELABORATE: The SCOPE of a function can be used as a PRIVATE NAMESPACE for a module. Therefore, the scope of a function is called a module function.

32.

To define each of the set classes as a property of the sets object (namespace) for the module, the statement is(a) sets = sets.AbstractEnumerableSet.extend();(b) sets.SingletonSet = sets.AbstractEnumerableSet.extend(…);(c) sets.SingletonSet = sets.extend(…);(d) sets = sets.extend(…);This question was posed to me during a job interview.The origin of the question is Modules in JavaScript topic in portion Classes and Modules in JavaScript of JavaScript

Answer»

The correct answer is (b) sets.SingletonSet = sets.AbstractEnumerableSet.EXTEND(…);

To explain I would SAY: Singleton is an object which can only be instantiated once. The extend keyword is used in class declarations or class expressions to create a class which is a CHILD of another class. The sets object is the namespace for the module, and we define each of the set classes as a property of this object.

33.

The maximum number of global symbols a module can define is ____________(a) 2(b) 3(c) 1(d) 4This question was posed to me in exam.I'd like to ask this question from Modules in JavaScript in portion Classes and Modules in JavaScript of JavaScript

Answer»

Correct OPTION is (C) 1

For explanation: GENERALLY, the various modules are allowed to run in the pristine (or near pristine) ENVIRONMENT that it expects. The modules should minimize the number of global symbols they define – ideally, no MODULE should define more than one.

34.

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)The question was posed to me in quiz.My query is from Augmentation of Classes in division Classes and Modules in JavaScript of JavaScript

Answer»

The CORRECT answer is (b) HTMLElement.prototype

To explain I would say: 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.

35.

The functions provide() and require() of Dojo toolkit and Google’s Closure library are used for ___________(a) declaring and loading modules(b) declaring functions(c) declaring modules(d) loading modulesThe question was asked during a job interview.Query is from Modules in JavaScript in division Classes and Modules in JavaScript of JavaScript

Answer»

Correct option is (a) declaring and loading modules

To explain I would SAY: Both the Dojo toolkit and GOOGLE’s Closure library DEFINE PROVIDE() and require() FUNCTIONS for declaring and loading modules.

36.

How can we make methods available on all objects?(a) Object.add(methods)(b) Object.methods(add)(c) Object.add.methods(…)(d) Object.prototypeI have been asked this question in final exam.The query is from Augmentation of Classes in chapter Classes and Modules in JavaScript of JavaScript

Answer» RIGHT choice is (d) Object.prototype

Easiest 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.
37.

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); };I got this question in exam.My doubt stems from Augmentation of Classes topic in division Classes and Modules in JavaScript of JavaScript

Answer»

The correct answer is (a) Complex.prototype.conj = FUNCTION() { RETURN new Complex(this.r, -this.i); };

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.

38.

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 ivThe question was posed to me in examination.Question is from Augmentation of Classes in section Classes and Modules in JavaScript of JavaScript

Answer»

Right ANSWER is (b) ii, III and iv only

The best 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).

39.

The class that represents the regular expressions is ________(a) RegExpObj(b) RegExpClass(c) RegExp(d) StringExpThe question was asked in an international level competition.My doubt stems from Augmentation of Classes topic in division Classes and Modules in JavaScript of JavaScript

Answer» CORRECT answer is (c) REGEXP

The explanation is: 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.
40.

Which variables are used internally in object methods and are also globally visible?(a) Object properties(b) Variable properties(c) Method properties(d) Internal propertiesI have been asked this question in final exam.My query is from Augmentation of Classes topic in section Classes and Modules in JavaScript of JavaScript

Answer»

Correct choice is (b) VARIABLE PROPERTIES

The explanation is: 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.

41.

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 objectThe question was asked in my homework.My query is from Augmentation of Classes topic in chapter Classes and Modules in JavaScript of JavaScript

Answer» RIGHT answer is (d) PROTOTYPE object

For 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.
42.

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 objectI got this question in an online interview.Question is taken from Augmentation of Classes topic in section Classes and Modules in JavaScript of JavaScript

Answer»

Correct option is (C) Constructor object, Prototype object, INSTANCE object

Easiest 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.

43.

If A is the superclass and B is the subclass, then subclass inheriting the superclass can be represented as _________(a) B=inherit(A);(b) B=A.inherit();(c) B.prototype=inherit(A);(d) B.prototype=inherit(A.prototype);I got this question during an online interview.My doubt stems from Classes in JavaScript topic in division Classes and Modules in JavaScript of JavaScript

Answer»

The correct ANSWER is (c) B.PROTOTYPE=INHERIT(A);

The explanation: inherit() function is a predefined function in javascript which is used to inherit properties of another class. The subclass B inherits the prototype of the class A.

44.

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 methodsThe question was posed to me during an online exam.The question is from Augmentation of Classes in division Classes and Modules in JavaScript of JavaScript

Answer»

Right choice is (b) INSTANCE fields, Instance methods, Class fields, Class methods

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.

45.

The snippet that filters the filtered set is __________(a) var t=new FilteredSet(s, {function(s) {return !(x instanceof Set);});(b) var t=new FilteredSet{function(s) {return !(x instanceof Set);});(c) var t=new FilteredSet(s, {function(s) {return (x instanceof Set);});(d) var t=new FilteredSet(s, {function(s) {return x;});The question was asked in an interview for internship.I'd like to ask this question from Classes in JavaScript topic in division Classes and Modules in JavaScript of JavaScript

Answer»

The correct answer is (a) var t=new FilteredSet(s, {function(s) {return !(X INSTANCEOF Set);});

Best explanation: The instanceof operator is used to check the type of an object at run TIME. The instanceof operator returns a boolean VALUE that indicates if an object is an instance of a particular class.

46.

When a class B can extend another class A, we say that?(a) A is the superclass and B is the subclass(b) B is the superclass and A is the subclass(c) Both A and B are the superclass(d) Both A and B are the subclassThe question was asked in an internship interview.I'd like to ask this question from Classes in JavaScript in chapter Classes and Modules in JavaScript of JavaScript

Answer»

The correct ANSWER is (a) A is the SUPERCLASS and B is the SUBCLASS

For EXPLANATION: Superclass is the class from which subclasses are defined. Subclasses are also called EXTENSIONS of superclass.therefore in the above scenario A will be superclass and B will be subclass.

47.

The property of JSON() method is __________(a) it can be invoked manually as object.JSON()(b) it will be automatically invoked by the compiler(c) it is invoked automatically by the JSON.stringify() method(d) it cannot be invoked in any formI got this question at a job interview.Enquiry is from Classes in JavaScript in chapter Classes and Modules in JavaScript of JavaScript

Answer»

The correct choice is (c) it is INVOKED automatically by the JSON.stringify() method

Explanation: A common use of JSON is to exchange DATA to/from a web server. When sending data to a web server, the data has to be a STRING. In that CASE json.strigify() is used to CONVERT a javascript object into a string.

48.

The meaning for Augmenting classes is that ___________(a) objects inherit prototype properties even in a dynamic state(b) objects inherit prototype properties only in a dynamic state(c) objects inherit prototype properties in the static state(d) object doesn’t inherit prototype properties in the static stateThe question was posed to me in an online quiz.The question is from Classes in JavaScript in portion Classes and Modules in JavaScript of JavaScript

Answer»

The CORRECT choice is (a) objects inherit prototype properties even in a dynamic state

To EXPLAIN: JavaScript’s prototype-based inheritance mechanism is dynamic an object inherits properties from its prototype, even if the prototype CHANGES after the object is created. This means that we can augment JavaScript CLASSES simply by adding NEW methods to their prototype objects.

49.

The basic difference between JavaScript and Java is _________(a) There is no difference(b) Functions are considered as fields(c) Variables are specific(d) Functions are values, and there is no hard distinction between methods and fieldsI have been asked this question by my school principal while I was bunking the class.This intriguing question originated from Classes in JavaScript topic in section Classes and Modules in JavaScript of JavaScript

Answer»

The correct answer is (d) Functions are values, and there is no hard DISTINCTION between methods and fields

Easiest explanation: JAVA is an OOP programming language while JavaScript is an OOP scripting language. The BASIC DIFFERENCE between JavaScript and Java is that the functions are values, and there is no hard distinction between methods and fields.

50.

The keyword or the property that you use to refer to an object through which they were invoked is _________(a) from(b) to(c) this(d) objectThis question was addressed to me by my school principal while I was bunking the class.Enquiry is from Classes in JavaScript topic in chapter Classes and Modules in JavaScript of JavaScript

Answer» RIGHT CHOICE is (c) this

To explain I WOULD say: ‘this’ KEYWORD is used to refer to the object through which the properties or methods were invoked. This use of ‘this’ is a fundamental characteristic of the methods of any class.