Javascript - Quiz - Jan 2016

Description

Javascript Quiz for emids participants
arunram.krish
Quiz by arunram.krish, updated more than 1 year ago
arunram.krish
Created by arunram.krish almost 9 years ago
438
2

Resource summary

Question 1

Question
What are the values that evaluate to false when used in a Boolean expression?
Answer
  • Only null
  • Only undefined
  • Only “”
  • Only NaN
  • All of the above

Question 2

Question
Which of the following statements are TRUE?
Answer
  • 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”

Question 3

Question
What are the primitive types in Javascript?
Answer
  • Int, float, double, char, Boolean
  • Int, float, double, char, String, Boolean
  • Number, String, Boolean
  • Number, char, String, Boolean

Question 4

Question
How do you create an Object with a prototype object assigned to variable “proto”?
Answer
  • var myObject = new Object(proto);
  • var myObject = new Object(); myObject.prototype = proto;
  • var myObject = Object.create(proto);
  • var myObject[“prototype”] = proto;

Question 5

Question
How to create a Javascript array?
Answer
  • Only var myArray = new Array();
  • Only var myArray = [];
  • var myArray[] = new Object();
  • Both a & b

Question 6

Question
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?
Answer
  • function SubClass() { super(); }
  • function SubClass() { ParentClass(); }
  • function SubClass() { new ParentClass(); }
  • function SubClass() { ParentClass.apply(this, arguments); }
  • All of the above

Question 7

Question
How do you use function to create a singleton object?
Answer
  • 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

Question 8

Question
What is a Closure?
Answer
  • 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

Question 9

Question
How do you invoke a callback function within a loop with loop index variable as argument after 500 milliseconds?
Answer
  • 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

Question 10

Question
How do you add a function “removeDuplicates” (already defined with this name) accessible from all Array objects?
Answer
  • 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.

Question 11

Question
How does Javascript object inherit properties and methods defined in ancestor classes?
Answer
  • Through constructor inheritance
  • Using extends keyword
  • Through prototype chaining
  • There is no automatic support in Javascript. Properties and behaviors need to be explicitly added

Question 12

Question
What is the difference between “!=” and “!==”?
Answer
  • “!==” 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

Question 13

Question
How do you pass JSON data as part of HTTP POST request body in AJAX request?
Answer
  • xhr.send(JSON.stringify(myJsonObject));
  • xhr.open(‘post’, myUrl, JSON.stringify(myJsonObject));
  • xhr.open(JSON.stringify(myJsonObject));
  • xhr.open(‘post’, myUrl + “?” + JSON.stringify(myJsonObject));

Question 14

Question
How do you create a “div” element with id “childDiv” and append it to parent div with id “parentDiv” using DOM API?
Answer
  • 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);

Question 15

Question
Choose the best practices that need to be adopted in production environment to improve the performance?
Answer
  • 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
Show full summary Hide full summary

Similar

Computing Hardware - CPU and Memory
ollietablet123
SFDC App Builder 2
Parker Webb-Mitchell
Data Types
Jacob Sedore
Intake7 BIM L1
Stanley Chia
Software Processes
Nurul Aiman Abdu
Design Patterns
Erica Solum
CCNA Answers – CCNA Exam
Abdul Demir
Abstraction
Shannon Anderson-Rush
Spyware
Sam2
HTTPS explained with Carrier Pigeons
Shannon Anderson-Rush
Translations and transformations of functions
Christine Laurich