A
B
C
D
100

Your application prompts the user to enter his or her age, which is placed in an age

variable. A user ran the application and entered I Don’t Know for the age. The application

then multiplies age by two. What is the result?

A. undefined

B. null

C. NaN

D. infinity

Correct answer: C

A. Incorrect: The undefined value means that the variable has never been initialized.

B. Incorrect: The null value means that the variable was explicitly set to have no

value.

C. Correct: When performing a mathematical operation on a nonnumeric value, NaN

(not a number) will result.

D. Incorrect: The Infinity value will result when your value exceeds

1.7976931348623157E + 10308.

100

Where should your JavaScript code be placed?

A. In the <head> element of your HTML document.

B. Just before the </body> tag.

C. You should always place your JavaScript code in separate files, external to your

HTML document.

D. Inside the <body> element, at the top.

Correct answer: C

A. Incorrect: Placing your JavaScript code in the <head> element does not promote

reuse, and inline code might reference elements that are not yet loaded.

B. Incorrect: Placing your JavaScript code in the </body> tag does not promote

reuse.

C. Correct: Placing your JavaScript code in separate files, external to your HTML

document, promotes reuse.

D. Incorrect: Placing your JavaScript code in the <body> element does not promote

reuse, and inline code might reference elements that are not yet loaded.

100

How is inheritance supported in JavaScript?

A. You replace the prototype of the child object with a new instance of the parent

object and then replace the prototype constructor with the child constructor.

B. You call the createChild method on the parent object.

C. You call the setParent method on the child object.

D. JavaScript does not support inheritance.

Correct answer: A

A. Correct: You replace the prototype of the child object with a new instance of

the parent object and then replace the prototype constructor with the child

constructor.

B. Incorrect: The createChild method is not a valid method.

C. Incorrect: The setParent method is not a valid method.

D. Incorrect: JavaScript does support inheritance by replacing the prototype of the

child object with a new instance of the parent object and then replacing the prototype constructor with the child constructor.

100

Which method creates a resolved promise object?

A. resolve()

B. done()

C. $.when()

D. $.Deferred().

Correct answer: C

A. Incorrect: The resolve method resolves an existing promise object, but it doesn’t

create a new resolved promise object.

B. Incorrect: The done method executes code upon success of a promise object, but

it does not create a resolved promise object.

C. Correct: The $.when() method creates a resolved promise object.

D. Incorrect: The $.Deferred() method creates an unresolved promise object.

200

Which of the following represent valid variable declarations? (Choose all that apply.)

A. var switch;

B. var myChar;

C. var $cost;

D. var _total;

E. var 1to1;

F. var tooGood4u;

Correct answers: B, C, D, and F

A. Incorrect: You cannot use a JavaScript keyword for a variable name, and switch is a

JavaScript keyword.

B. Correct: The myChar variable name is valid.

C. Correct: JavaScript allows a variable name to contain the dollar sign, so the $cost

variable name is valid.

D. Correct: JavaScript allows a variable name to contain the underscore, so the _total

variable name is valid.

E. Incorrect: Variable names cannot begin with a number.

F. Correct: Variable names can contain numbers but cannot begin with a number.

200

You have two arrays of strings, customers and employees, and you want to combine

them to create a contacts array. Which method would be most suitable for this task?

A. concat

B. join

C. push

D. splice

Correct answer: A

A. Correct: Concat concatenates multiple arrays and produces a resultant array.

B. Incorrect: Join creates a string from the items in the array.

C. Incorrect: Push adds a single item to the end of the array.

D. Incorrect: Splice adds and removes items from an array and produces a resultant

array, but you must add the items one by one, not as an array.

200

You want to locate all the elements on your webpage that are assigned the CSS class

name Hidden. Which jQuery statement can you use?

A. var hidden = $ (‘#Hidden’);

B. var hidden = $ (‘.Hidden’);

C. var hidden = $ (‘Hidden’);

D. var hidden = $(‘class=Hidden’);

Correct answer: B

A. Incorrect: The use of the hash (#) symbol in the CSS selector indicates that you

want to locate an element based on its id.

B. Correct: The use of the period (.) in the CSS selector indicates that you want to

locate the elements that match the CSS class name.

C. Incorrect: Supplying a name for a CSS selector indicates that you want to locate

the elements that have that tag name.

D. Incorrect: The var hidden = $(‘class=Hidden’); syntax is invalid.

200

Which method do you call to subscribe to the successful completion of an asynchronous

operation?

A. done

B. always

C. complete

D. success

Correct answer: A

A. Correct: The done method executes code upon successful completion.

B. Incorrect: The alway method executes code regardless of success or failure.

C. Incorrect: The complete method does not exist.

D. Incorrect: The success method does not exist.

300

In your application, you want to display a personalized message to the user, if the

user’s name is populated, in the userName variable, but if userName is empty, you

want to use Valued User instead. How can you accomplish this most efficiently?

A. var personalized = ‘Hello ‘ + (userName ?? ‘Valued User’);

B. var personalized = ‘Hello ‘ + (userName || ‘Valued User’);

C. var personalized = ‘Hello ‘ + (userName && ‘Valued User’);

D. var personalized = ‘Hello ‘ + (userName + ‘Valued User’);

Correct answer: B

A. Incorrect: The use of ?? causes a syntax error.

B. Correct: The use of || causes Valid User to be displayed if userName has no value.

C. Incorrect: The use of && displays nothing if userName has no value.

D. Incorrect: The use of + causes Valid User to be displayed if userName has no value,

but it also displays the userName and Valid User together when the userName has

a value.

300

You want to obtain a list of all elements whose tag name is div, and you need to

retrieve this list as quickly as possible. Which function is most appropriate for this task?

A. getElementsByName

B. querySelectorAll

C. getElementsByTagName

D. getElementsByClass

Correct answer: C

A. Incorrect: getElementsByName retrieves a live NodeList of elements based on the

element’s name attribute, not on the tag name.

B. Incorrect: querySelectorAll is capable of retrieving the elements by tag name, but

returns a static NodeList, which does not perform as well as functions that return a

live NodeList.

C. Correct: getElementsByTagName retrieves a live NodeList of elements based on

the element’s tag name.

D. Incorrect: getElementsByClass retrieves a live NodeList of elements based on the

CSS class name.

300

You are interested in writing event-driven JavaScript code that will work on most

browsers without writing browser-specific code. How can you accomplish this?

A. Use the jQuery library to help.

B. Use only JavaScript statements that are the same across all browsers.

C. Do not use any JavaScript.

D. It’s impossible to write event-driven JavaScript code that is not browser-specific.

Correct answer: A

A. Correct: Using jQuery will help you create event-driven, browser-independent

code.

B. Incorrect: The code for creating and subscribing to events is browser-specific.

C. Incorrect: You need to use JavaScript to write event-driven code.

D. Incorrect: Use the jQuery library to write browser-independent code.

300

Which method do you call on the deferred object to indicate a change in progress?

A. progress

B. notify

C. done

D. resolve

Correct answer: B

A. Incorrect: The progress method executes code when progress has changed; it does

not to indicate a change in progress.

B. Correct: The notify method indicates a change in progress.

C. Incorrect: The done method executes code when completed but does not indicate

a change in progress.

D. Incorrect: The resolve method indicates success, not a change in progress.

400

You are creating a new Windows 8 application, and you want to set up TDD for your

JavaScript code. Which testing framework will you use?

A. QUnit

B. QUnit-Metro

C. Microsoft Test

D. NUnit

Correct answer: B

A. Incorrect: QUnit is for testing JavaScript for the web, not Windows 8.

B. Correct: QUnit-Metro is a variation of QUint, which supports Windows 8.

C. Incorrect: Microsoft Test does not support JavaScript.

D. Incorrect: NUnit does not support JavaScript.

400

What is the blueprint for an object called?

A. property

B. method

C. class

D. event

Correct answer: C

A. Incorrect: A property is a variable that’s defined on an object.

B. Incorrect: A method is a function that’s defined on an object.

C. Correct: A class is a blueprint for an object.

D. Incorrect: An event takes place from external input, usually from user input.

400

You are interested in locating all <p> elements on your webpage, so your statement is

var paragraphs = $(‘p’). Which line of code would confirm whether at least one element

is found?

A. if( paragraphs.exists)

B. if( paragraphs==null)

C. if( paragraphs.length)

D. if( paragraphs.count > 0)

Correct answer: C

A. Incorrect: jQuery does not have an exists property.

B. Incorrect: Even if no elements are found, jQuery will return a wrapper object.

C. Correct: If no elements are found, the length property will be 0, which converts to

a Boolean false.

D. Incorrect: jQuery does not have a count property.

400

 Explain “this” keyword in JavaScript

this” is not a variable. It is a keyword. You cannot change the value of this. It refers to the global object in all the global code.

We know, how to create the multiple objects. We can use Object Constructor function. We’ll use this keyword to create a property, which belongs to a function.

function Automobile(engine, fuel, tyres) {

    this.engine = engine;

    this.fuel = fuel;

    this.tyres = tyres;

}

var car = new Automobile(true, true, 4);

var bike = new Automobile(true, true, 2);

This refers to the parent object in the body of the function:

var counter = {

    val: 0,

    increment: function() {

        this.val += 1;

    }

};

counter.increment();

console.log(counter.val); // 1

counter['increment']();

console.log(counter.val); // 2  

500

What are the steps for TDD?

A. Write the passing test, write the code, run the test again to validate that it still

passes.

B. Write the failing test, write the code, run the test again to validate that it passes.

C. Write the code, write the test to validate that it passes, run the test again to validate

that it still passes.

D. Write the passing test, write the code, break the code, run the test again to validate

that it fails.

Correct answer: B

A. Incorrect: You need to write a failing test first so you can see the test pass after

you write the code.

B. Correct: You write a failing test and then write code that makes the test pass; then

run the test again to validate that it passes.

C. Incorrect: You should never write code without first writing a test that fails.

D. Incorrect: If you write a passing test first, the code cannot be tested for success.

500

What does JavaScript use as a starting object when constructing a new object?

A. prototype

B. property

C. class

D. event

Correct answer: A

A. Correct: The prototype is the starting object that is cloned when creating a new

object.

B. Incorrect: A property is a variable that’s defined on an object.

C. Incorrect: A class is a blueprint for an object.

D. Incorrect: An event takes place from external input, usually from user input.

500

Which method chains asynchronous operations?

A. pipe()

B. done()

C. resolve()

D. always()

Correct answer: A

A. Correct: Use the pipe method to chain asynchronous operations because it provides access to progress, failure, success, and complete.

B. Incorrect: The done method executes code when completed but does not provide

access to failure, progress, and complete.

C. Incorrect: The resolve method indicates success but is not used for chaining.

D. Incorrect: The always method executes on completion regardless of success or

failure. This method does not provide access to progress, success, or failure.

500

Explain “delete” keyword in JavaScript.

When we work on the large Applications, we work with many objects. We are familiar with the problems like memory leak, performance of an Application is not good and similar issues arise at a later stage. I always recommend, that we need to know, how much memory, are we consuming in our Application.

Ex- Chrome provides a quick way to look into the memory usage.

The main advantage is to delete an unwanted property from an object.

var automobile = {engine: true, fuel: true, tyres:2 };

var car = Object.create (automobile); //car is instanceof automobile

console.log (car.tyres); // 2 it inherits from parent class

//as we know car has own tyres then we can create own property of car object

car.tyres = 4; // will make own tyre property of car object