Pregunta 1
Pregunta
What are the values that evaluate to false when used in a Boolean expression?
Respuesta
-
Only null
-
Only undefined
-
Only “”
-
Only NaN
-
All of the above
Pregunta 2
Pregunta
Which of the following statements are TRUE?
Respuesta
-
When a variable that is not declared is used it returns “undefined”
-
When a variable that is not declared is used it throws ReferenceError
-
A function that is defined below in the later part of the script can be invoked / referred
-
A variable that is not assigned any value returns “undefined”
Pregunta 3
Pregunta
What are the primitive types in Javascript?
Respuesta
-
Int, float, double, char, Boolean
-
Int, float, double, char, String, Boolean
-
Number, String, Boolean
-
Number, char, String, Boolean
Pregunta 4
Pregunta
How do you create an Object with a prototype object assigned to variable “proto”?
Respuesta
-
var myObject = new Object(proto);
-
var myObject = new Object();
myObject.prototype = proto;
-
var myObject = Object.create(proto);
-
var myObject[“prototype”] = proto;
Pregunta 5
Pregunta
How to create a Javascript array?
Pregunta 6
Pregunta
How do you invoke parent class’ constructor (by name ParentClass) from a sub class constructor (by name SubClass) to inherit properties defined in ParentClass in the new SubClass object?
Respuesta
-
function SubClass() { super(); }
-
function SubClass() { ParentClass(); }
-
function SubClass() { new ParentClass(); }
-
function SubClass() { ParentClass.apply(this, arguments); }
-
All of the above
Pregunta 7
Pregunta
How do you use function to create a singleton object?
Respuesta
-
var mySingleton = function() {
function SingletonClass() {
}
return new SingletonClass();
};
-
b. var mySingleton = (function() {
function SingletonClass() {
}
return new SingletonClass();
})();
-
var mySingleton = {};
-
It is not possible to create a singleton object using function
Pregunta 8
Pregunta
What is a Closure?
Respuesta
-
A special scope variable assigned to function that holds states / variables that was accessible at the time of defining this inner function
-
Closure is a property of function that needs to be explicitly assigned within the body of function
-
Closure is a global function along with global variables
-
Closure is an inner function along with global variables
Pregunta 9
Pregunta
How do you invoke a callback function within a loop with loop index variable as argument after 500 milliseconds?
Respuesta
-
function invokeCallback(callback) {
for(var i=0;i<5;i++) {
setTimeout(callback(i), 500);
}
}
-
function invokeCallback(callback) {
for(var i=0;i<5;i++) {
setTimeout(function() {callback(i)}, 500);
}
}
-
function invokeCallback(callback) {
function invoker(i) {
return function() { callback(i); }
}
for(var i=0;i<5;i++) {
setTimeout(invoker(), 500);
}
}
-
None of the above
Pregunta 10
Pregunta
How do you add a function “removeDuplicates” (already defined with this name) accessible from all Array objects?
Respuesta
-
Array.removeDuplicates = removeDuplicates;
-
Array.prototype.removeDuplicates = removeDuplicates
-
var myArray = new Array() {
this.removeDuplicates = removeDuplicates;
}
-
Array is a predefined type in javascript. It cannot be modified.
Pregunta 11
Pregunta
How does Javascript object inherit properties and methods defined in ancestor classes?
Respuesta
-
Through constructor inheritance
-
Using extends keyword
-
Through prototype chaining
-
There is no automatic support in Javascript. Properties and behaviors need to be explicitly added
Pregunta 12
Pregunta
What is the difference between “!=” and “!==”?
Respuesta
-
“!==” will not check for null or undefined or “” while “!=” checks
-
“!=” does not convert type while “!==” does convert type
-
“!==” does not do type coercion while “!= does type coercion
-
Both operators are same
Pregunta 13
Pregunta
How do you pass JSON data as part of HTTP POST request body in AJAX request?
Respuesta
-
xhr.send(JSON.stringify(myJsonObject));
-
xhr.open(‘post’, myUrl, JSON.stringify(myJsonObject));
-
xhr.open(JSON.stringify(myJsonObject));
-
xhr.open(‘post’, myUrl + “?” +
JSON.stringify(myJsonObject));
Pregunta 14
Pregunta
How do you create a “div” element with id “childDiv” and append it to parent div with id “parentDiv” using DOM API?
Respuesta
-
var childDiv = window.createElement(“div”);
window.getElementById(“parentDiv”).appendChild(childDiv);
-
var childDiv = document.newElement(“div”);
document.getElementById(“parentDiv”).appendChild(childDiv);
-
var childDiv = document.createElement(“<div
id=”childDiv”);
window.getElementById(“parentDiv”).appendChild(childDiv);
-
var childDiv = document.createElement(“div”);
childDiv.setAttribute(“id”, “childDiv”);
document.getElementById(“parentDiv”).appendChild(childDiv);
Pregunta 15
Pregunta
Choose the best practices that need to be adopted in production environment to improve the performance?
Respuesta
-
Keep Javascript files separate and download them individually
-
Concatenate multiple javascript files into single javascript file and refer to this javascript in the script tag
-
Use descriptive variable names and detailed comments
-
Minify javascript to reduce the overall size of Javascript file downloaded by browser
-
Use CDN site over local Javascript files