JavaScript Questions and Answers for Campus interviews on “Comparison of Core JavaScript versus Frameworks – II”.
1. Which of the following is not a JavaScript framework?
a) Rico
b) Prototype
c) Joco
d) DoJo
Answer: d
Clarification: Dojo Toolkit is an open source modular JavaScript library (or more specifically JavaScript toolkit) designed to ease the rapid development of cross-platform, JavaScript/Ajax-based applications and web sites. Rico was an open-source JavaScript library for developing rich internet applications with Ajax.
2. What is the purpose of the Math method toSource()?
a) Returns the string “Math”
b) Sends the source to the Math Library
c) Returns the value of the object
d) Returns an integer value
Answer: a
Clarification: The method Math.toSource() returns the string “Math”. But this method does not work with many browsers like IE. The toSource() method returns a string representing the source code of the object.
3. What will be the output of the following JavaScript code?
var o = new F(); o.constructor === F
a) false
b) true
c) 0
d) 1
Answer: b
Clarification: ’===’ sign is used for comparing the type of values. The result is true if the constructor property specifies the class.
4. How many static methods does a Date object have?
a) 3
b) 5
c) 4
d) 2
Answer: d
Clarification: Date objects are created with the new Date() constructor. The Date object defines two static methods namely Date.parse() and Date.UTC().
5. Which of the following are static methods in JavaScript?
a) Date.parse()
b) Date.UTC()
c) Both Date.parse() and Date.UTC()
d) Date.clear()
Answer: c
Clarification: Date objects are created with the new Date() constructor. Date.parse() parses a string representation of a date and time and returns the internal millisecond representation of that date. Date.UTC() Returns the millisecond representation of the specified UTC date and time.
6. What will be the work of the getAvg in the following JavaScript function?
<script> function getAvg(){ var avg = 0; for(var x = 0; x < 200; x++){ avg += x; } return(avg/200); }
a) Multiples values from 0 to 200
b) Adds values from 0 to 200
c) Simply traverses with no operation
d) Find the average of 199 numbers
Answer: d
Clarification: For loop is used in the above code for adding the numbers. The above code performs the average calculation of numbers from 0 to 199.
7. If we have an object r and want to know if it is a Range object, we can write ______________
a) r typeof Range
b) r is Range
c) r equals Range
d) r instanceof Range
Answer: d
Clarification: To know the range object r instanceof range is used. The r instanceof Range returns true if r inherits from Range.prototype. The instanceof operator does not actually check whether r was initialized by the Range constructor.
8. What is the property to access the first child of a node?
a) timestamp.Child1
b) timestamp.Child(1)
c) timestamp.Child(0)
d) timestamp.firstChild
Answer: d
Clarification: The firstChild property returns the first child node of the specified node, as a Node object. The first child of a node can be accessed using the firstChild property.
9. Which of the following is not an object?
a) Element
b) Location
c) Position
d) Window
