Questão 1
Questão
What are the values that evaluate to false when used in a Boolean expression?
Responda
-
Only null
-
Only undefined
-
Only “”
-
Only NaN
-
All of the above
Questão 2
Questão
Which of the following statements are TRUE?
Responda
-
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”
Questão 3
Questão
What are the primitive types in Javascript?
Responda
-
Int, float, double, char, Boolean
-
Int, float, double, char, String, Boolean
-
Number, String, Boolean
-
Number, char, String, Boolean
Questão 4
Questão
How do you create an Object with a prototype object assigned to variable “proto”?
Responda
-
var myObject = new Object(proto);
-
var myObject = new Object();
myObject.prototype = proto;
-
var myObject = Object.create(proto);
-
var myObject[“prototype”] = proto;
Questão 5
Questão
How to create a Javascript array?
Questão 6
Questão
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?
Responda
-
function SubClass() { super(); }
-
function SubClass() { ParentClass(); }
-
function SubClass() { new ParentClass(); }
-
function SubClass() { ParentClass.apply(this, arguments); }
-
All of the above
Questão 7
Questão
How do you use function to create a singleton object?
Responda
-
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
Questão 8
Questão
What is a Closure?
Responda
-
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
Questão 9
Questão
How do you invoke a callback function within a loop with loop index variable as argument after 500 milliseconds?
Responda
-
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
Questão 10
Questão
How do you add a function “removeDuplicates” (already defined with this name) accessible from all Array objects?
Responda
-
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.
Questão 11
Questão
How does Javascript object inherit properties and methods defined in ancestor classes?
Responda
-
Through constructor inheritance
-
Using extends keyword
-
Through prototype chaining
-
There is no automatic support in Javascript. Properties and behaviors need to be explicitly added
Questão 12
Questão
What is the difference between “!=” and “!==”?
Responda
-
“!==” 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
Questão 13
Questão
How do you pass JSON data as part of HTTP POST request body in AJAX request?
Responda
-
xhr.send(JSON.stringify(myJsonObject));
-
xhr.open(‘post’, myUrl, JSON.stringify(myJsonObject));
-
xhr.open(JSON.stringify(myJsonObject));
-
xhr.open(‘post’, myUrl + “?” +
JSON.stringify(myJsonObject));
Questão 14
Questão
How do you create a “div” element with id “childDiv” and append it to parent div with id “parentDiv” using DOM API?
Responda
-
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);
Questão 15
Questão
Choose the best practices that need to be adopted in production environment to improve the performance?
Responda
-
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