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