Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 122

Preview Question Pool Questions - Chapter 8 Questions

1) jQuery is
When taking the question, it would appear as:
jQuery is
Question options:
a programming language
a part of the CSS3 specification
an open-source JavaScript library
an extension of the Chrome browser
When grading the question, it would appear as:
jQuery is

a programming language
a part of the CSS3 specification

an open-source JavaScript library

an extension of the Chrome browser

2) Which of the following statements about a Content Delivery


Network (CDN) is true?
When taking the question, it would appear as:
Which of the following statements about a Content Delivery Network (CDN) is true?
Question options:
It allows you to get jQuery from another website and include it in your application.
It allows you to download jQuery and include it in your application.
It can only be used by the modern browsers.
It works even if you’re not connected to the Internet.
When grading the question, it would appear as:
Which of the following statements about a Content Delivery Network (CDN) is true?

It allows you to get jQuery from another website and include it in your application.
It allows you to download jQuery and include it in your application.
It can only be used by the modern browsers.
It works even if you’re not connected to the Internet.

3) You include the jQuery library in your website by coding a


When taking the question, it would appear as:
You include the jQuery library in your website by coding a
Question options:
head element
body element
script element
link element
When grading the question, it would appear as:
You include the jQuery library in your website by coding a

head element
body element

script element

link element

4) A jQuery selector includes all but one of the following.


Which one is it?
When taking the question, it would appear as:
A jQuery selector includes all but one of the following. Which one is it?
Question options:
$ sign
quotation marks
parentheses
dot operator
When grading the question, it would appear as:
A jQuery selector includes all but one of the following. Which one is it?

$ sign
quotation marks
parentheses

dot operator

5) Which of the following expressions gets the value of a text


box with an id of “message”?
When taking the question, it would appear as:
Which of the following expressions gets the value of a text box with an id of “message”?
Question options:
$("#message").text

$("#message").text()

$("#message").val()

$("#message").nodeValue()

When grading the question, it would appear as:


Which of the following expressions gets the value of a text box with an id of “message”?
$("#message").text

$("#message").text()

$("#message").val()

$("#message").nodeValue()

6) Which of the following statements sets the text of a <p>


element with an id of “ship”
When taking the question, it would appear as:
Which of the following statements sets the text of a <p> element with an id of “ship”
Question options:
$("#ship").text = "Shipping is free.";

$("#ship").text("Shipping is free.");

$("#ship").val("Shipping is free.");

$("#ship").nodeValue("Shipping is free.");

When grading the question, it would appear as:


Which of the following statements sets the text of a <p> element with an id of “ship”
$("#ship").text = "Shipping is free.";

$("#ship").text("Shipping is free.");

$("#ship").val("Shipping is free.");

$("#ship").nodeValue("Shipping is free.");

7) What is object chaining?


When taking the question, it would appear as:
What is object chaining?
Question options:
When you code each method in a separate statement.
When you code methods that do similar things in a group of statements.
When you use a single statement to call one method from another method.
When you pass one method to another method as a parameter.
When grading the question, it would appear as:
What is object chaining?

When you code each method in a separate statement.


When you code methods that do similar things in a group of statements.

When you use a single statement to call one method from another method.

When you pass one method to another method as a parameter.

8) Object chaining works because each method returns the


appropriate
When taking the question, it would appear as:
Object chaining works because each method returns the appropriate
Question options:
object
selector
method
event method
When grading the question, it would appear as:
Object chaining works because each method returns the appropriate
object

selector
method
event method

9) With jQuery, which of the following do you use to attach an


event handler?
When taking the question, it would appear as:
With jQuery, which of the following do you use to attach an event handler?
Question options:
selector
method
event method
script element
When grading the question, it would appear as:
With jQuery, which of the following do you use to attach an event handler?

selector
method

event method

script element

10) When does the ready() event handler run?


When taking the question, it would appear as:
When does the ready() event handler run?
Question options:
As soon as the browser starts.
As soon as the browser gets the HTTP response for the page.
As soon as the browser starts to load the page.
As soon as the browser builds the DOM.
When grading the question, it would appear as:
When does the ready() event handler run?
As soon as the browser starts.
As soon as the browser gets the HTTP response for the page.
As soon as the browser starts to load the page.

As soon as the browser builds the DOM.

11) What does the following jQuery code do?$("h2").prev();


When taking the question, it would appear as:
What does the following jQuery code do?
$("h2").prev();

Question options:
Gets the h2 element that precedes the current element
Gets the element in the HTML that precedes the selected h2 element
Gets the previous sibling of each selected h2 element
Gets the previous sibling of each selected h2 element that is also an h2 element
When grading the question, it would appear as:
What does the following jQuery code do?
$("h2").prev();

Gets the h2 element that precedes the current element


Gets the element in the HTML that precedes the selected h2 element

Gets the previous sibling of each selected h2 element

Gets the previous sibling of each selected h2 element that is also an h2 element

12) What does the following jQuery code do?$


("#image").attr("src", imageURL);
When taking the question, it would appear as:
What does the following jQuery code do?
$("#image").attr("src", imageURL);

Question options:
Gets the value of the src attribute for the element with an id of “image” and stores it in a variable named im
Sets the value of the src attribute for the element with an id of “image” to the value in a variable named ima
Gets the values of the src attribute for each element with a class of “image” and stores them in an array vari
Sets the values of the src attribute for each element with a class of “image” to the values in an array variable
When grading the question, it would appear as:
What does the following jQuery code do?
$("#image").attr("src", imageURL);

Gets the value of the src attribute for the element with an id of “image” and stores it in a
variable named imageURL
Sets the value of the src attribute for the element with an id of “image” to the value in a
variable named imageURL
Gets the values of the src attribute for each element with a class of “image” and stores
them in an array variable named imageURL
Sets the values of the src attribute for each element with a class of “image” to the values
in an array variable named imageURL

13) Which of the following methods would you use to remove


a class if it’s present or add a class if it isn’t present?
When taking the question, it would appear as:
Which of the following methods would you use to remove a class if it’s present or add a class
if it isn’t present?
Question options:
toggle()
toggleClass()
changeClass()
switchClass()
When grading the question, it would appear as:
Which of the following methods would you use to remove a class if it’s present or add a class
if it isn’t present?

toggle()

toggleClass()

changeClass()
switchClass()

14) Which of the following methods would you use to execute


a method for each element in an array?
When taking the question, it would appear as:
Which of the following methods would you use to execute a method for each element in an
array?
Question options:
html()
hide()
every()
each()
When grading the question, it would appear as:
Which of the following methods would you use to execute a method for each element in an
array?

html()
hide()
every()

each()

15) Which of the following events occurs when the user


moves the mouse pointer over an element and then clicks on
it?
When taking the question, it would appear as:
Which of the following events occurs when the user moves the mouse pointer over an element
and then clicks on it?
Question options:
click
mouseover
hover
all of the above
When grading the question, it would appear as:
Which of the following events occurs when the user moves the mouse pointer over an element
and then clicks on it?

click
mouseover
hover
all of the above

16) Code example 8-1$("#faqs h2").click( evt => { const h2


= evt.currentTarget; $(h2).toggleClass("minus"); if ($
(h2).attr("class") !== "minus") { $(h2).next().hide();
} &nb
When taking the question, it would appear as:
Code example 8-1
$("#faqs h2").click( evt => {
const h2 = evt.currentTarget;
$(h2).toggleClass("minus");
if ($(h2).attr("class") !== "minus") {
$(h2).next().hide();
}
else {
$(h2).next().show();
}
evt.preventDefault();
});

(Refer to code example 8-1) What does evt.currentTarget refer to in this code?
Question options:
The click() event method
The anonymous function for the click() event method
All h2 elements within the element with an id of “faqs”
The h2 element that was clicked
When grading the question, it would appear as:
Code example 8-1
$("#faqs h2").click( evt => {
const h2 = evt.currentTarget;
$(h2).toggleClass("minus");
if ($(h2).attr("class") !== "minus") {
$(h2).next().hide();
}
else {
$(h2).next().show();
}
evt.preventDefault();
});

(Refer to code example 8-1) What does evt.currentTarget refer to in this code?
The click() event method
The anonymous function for the click() event method
All h2 elements within the element with an id of “faqs”

The h2 element that was clicked

17) Code example 8-1$("#faqs h2").click( evt => { const h2


= evt.currentTarget; $(h2).toggleClass("minus"); if ($
(h2).attr("class") !== "minus") { $(h2).next().hide();
} &nb
When taking the question, it would appear as:
Code example 8-1
$("#faqs h2").click( evt => {
const h2 = evt.currentTarget;
$(h2).toggleClass("minus");
if ($(h2).attr("class") !== "minus") {
$(h2).next().hide();
}
else {
$(h2).next().show();
}
evt.preventDefault();
});

(Refer to code example 8-1) Assuming none of the h2 elements include a class attribute when
the application starts, what happens the first time the user clicks on an h2 element?
Question options:
A class named “minus” is added to the element and the element’s next sibling is displayed.
A class named “minus” is added to the element and the element’s next sibling is hidden.
Nothing happens because the click() event method is used instead of the on() event method.
Nothing happens because the event object isn’t passed to the function for the event handler.
When grading the question, it would appear as:
Code example 8-1
$("#faqs h2").click( evt => {
const h2 = evt.currentTarget;
$(h2).toggleClass("minus");
if ($(h2).attr("class") !== "minus") {
$(h2).next().hide();
}
else {
$(h2).next().show();
}
evt.preventDefault();
});

(Refer to code example 8-1) Assuming none of the h2 elements include a class attribute when
the application starts, what happens the first time the user clicks on an h2 element?

A class named “minus” is added to the element and the element’s next sibling is
displayed.
A class named “minus” is added to the element and the element’s next sibling is hidden.
Nothing happens because the click() event method is used instead of the on() event
method.
Nothing happens because the event object isn’t passed to the function for the event
handler.

18) Code example 8-1$("#faqs h2").click( evt => { const h2


= evt.currentTarget; $(h2).toggleClass("minus"); if ($
(h2).attr("class") !== "minus") { $(h2).next().hide();
} &nb
When taking the question, it would appear as:
Code example 8-1
$("#faqs h2").click( evt => {
const h2 = evt.currentTarget;
$(h2).toggleClass("minus");
if ($(h2).attr("class") !== "minus") {
$(h2).next().hide();
}
else {
$(h2).next().show();
}
evt.preventDefault();
});

(Refer to code example 8-1) What does the parameter named evt refer to?
Question options:
the jQuery object
the Event object
the click() event method
the selector
When grading the question, it would appear as:
Code example 8-1
$("#faqs h2").click( evt => {
const h2 = evt.currentTarget;
$(h2).toggleClass("minus");
if ($(h2).attr("class") !== "minus") {
$(h2).next().hide();
}
else {
$(h2).next().show();
}
evt.preventDefault();
});

(Refer to code example 8-1) What does the parameter named evt refer to?

the jQuery object

the Event object

the click() event method


the selector

Preview Question Pool Questions - Chapter 13 Questions

1) Which of the following operators does NOT perform type


coercion?
When taking the question, it would appear as:
Which of the following operators does NOT perform type coercion?
Question options:
>
===
>=
!=
When grading the question, it would appear as:
Which of the following operators does NOT perform type coercion?

>

===

>=
!=
2) What are the values of the two variables when the following
code executes?let result1 = (1 == "1");let result2 = (1 ===
"1");
When taking the question, it would appear as:
What are the values of the two variables when the following code executes?
let result1 = (1 == "1");
let result2 = (1 === "1");

Question options:
both variables are true
both variables are false
result1 is false and result2 is true
result1 is true and result2 is false
When grading the question, it would appear as:
What are the values of the two variables when the following code executes?
let result1 = (1 == "1");
let result2 = (1 === "1");

both variables are true


both variables are false
result1 is false and result2 is true

result1 is true and result2 is false

3) What is the difference between the break statement and the


continue statement in a loop?
When taking the question, it would appear as:
What is the difference between the break statement and the continue statement in a loop?
Question options:
The break statement ends a loop.
The continue statement ends the current iteration of a loop.
The continue statement ends a loop.
The break statement ends the current iteration of a loop.
The break statement is used in for loops.
The continue statement is used in while loops.
There is no difference.
When grading the question, it would appear as:
What is the difference between the break statement and the continue statement in a loop?

The break statement ends a loop.


The continue statement ends the current iteration of a loop.
The continue statement ends a loop.
The break statement ends the current iteration of a loop.
The break statement is used in for loops.
The continue statement is used in while loops.
There is no difference.

4) What is displayed when the following code executes?let


numbers = "";for (let i = 1; i <= 30; i++) { if( i % 2 === 0 )
{ continue; } else { numbers += i + " "; } }
When taking the question, it would appear as:
What is displayed when the following code executes?
let numbers = "";
for (let i = 1; i <= 30; i++) {
if( i % 2 === 0 ) {
continue;
} else {
numbers += i + " ";
}
}
alert(numbers);

Question options:
even numbers from 2 to 30
odd numbers from 1 to 29
an empty string
the number 1
When grading the question, it would appear as:
What is displayed when the following code executes?
let numbers = "";
for (let i = 1; i <= 30; i++) {
if( i % 2 === 0 ) {
continue;
} else {
numbers += i + " ";
}
}
alert(numbers);

even numbers from 2 to 30


odd numbers from 1 to 29
an empty string
the number 1

5) You can use a switch statement in place of an if statement


with multiple else if clauses
When taking the question, it would appear as:
You can use a switch statement in place of an if statement with multiple else if clauses
Question options:
any time
as long as the switch statement contains a default case
when several expressions are tested for equality with multiple values
when one expression is tested for equality with multiple values
When grading the question, it would appear as:
You can use a switch statement in place of an if statement with multiple else if clauses

any time
as long as the switch statement contains a default case
when several expressions are tested for equality with multiple values

when one expression is tested for equality with multiple values

6) If a case label of a switch statement doesn’t contain a break


statement, what will the code execution do?
When taking the question, it would appear as:
If a case label of a switch statement doesn’t contain a break statement, what will the code
execution do?
Question options:
Stop
Fall through to the default label
Fall through to the next label
Throw an error
When grading the question, it would appear as:
If a case label of a switch statement doesn’t contain a break statement, what will the code
execution do?

Stop
Fall through to the default label

Fall through to the next label

Throw an error

7) What is displayed when the following code executes?const


statusCode = "403";switch (statusCode) { case "200":
alert("OK"); break; case "403": &nbs
When taking the question, it would appear as:
What is displayed when the following code executes?
const statusCode = "403";
switch (statusCode) {
case "200":
alert("OK");
break;
case "403":
alert("Forbidden");
break;
case "404":
alert("Not Found");
break;
default:
alert("Unknown Status");
break;
}

Question options:
OK
Forbidden
Not Found
Unknown Status
When grading the question, it would appear as:
What is displayed when the following code executes?
const statusCode = "403";
switch (statusCode) {
case "200":
alert("OK");
break;
case "403":
alert("Forbidden");
break;
case "404":
alert("Not Found");
break;
default:
alert("Unknown Status");
break;
}

OK

Forbidden

Not Found
Unknown Status

8) Which of the following statements about the conditional


operator is NOT true?
When taking the question, it would appear as:
Which of the following statements about the conditional operator is NOT true?
Question options:
If the first operand is true, it returns the second operand.
If the first operand is false, it returns the third operand.
The third operand is optional.
It can be rewritten as an if statement.
When grading the question, it would appear as:
Which of the following statements about the conditional operator is NOT true?

If the first operand is true, it returns the second operand.


If the first operand is false, it returns the third operand.

The third operand is optional.

It can be rewritten as an if statement.

9) What is the value of the variable named highest after the


following code executes?let number = 20;let highest =
18;highest = (number > highest) ? number : highest;
When taking the question, it would appear as:
What is the value of the variable named highest after the following code executes?
let number = 20;
let highest = 18;
highest = (number > highest) ? number : highest;
Question options:
true

20

18

undefined

When grading the question, it would appear as:


What is the value of the variable named highest after the following code executes?
let number = 20;
let highest = 18;
highest = (number > highest) ? number : highest;

true

20

18

undefined

10) Which of the following conditional expressions evaluate to


true?
When taking the question, it would appear as:
Which of the following conditional expressions evaluate to true?
Question options:
(0)

("Mike")

("")

(null)

When grading the question, it would appear as:


Which of the following conditional expressions evaluate to true?
(0)

("Mike")

("")

(null)
11) What does the following code display?let country = "";let
valid = "";if (country) { valid = "Valid";} else { valid =
"Not valid";}alert(valid);
When taking the question, it would appear as:
What does the following code display?
let country = "";
let valid = "";
if (country) {
valid = "Valid";
} else {
valid = "Not valid";
}
alert(valid);

Question options:
false
Valid
Not valid
empty string
When grading the question, it would appear as:
What does the following code display?
let country = "";
let valid = "";
if (country) {
valid = "Valid";
} else {
valid = "Not valid";
}
alert(valid);

false
Valid

Not valid

empty string

12) Because the AND ( && ) and OR ( || ) operators use short


circuit evaluation, they
When taking the question, it would appear as:
Because the AND ( && ) and OR ( || ) operators use short circuit evaluation, they
Question options:
are unreliable
can only return Boolean values
can be used in selections to assign values to variables
can only be used in if and switch statements
When grading the question, it would appear as:
Because the AND ( && ) and OR ( || ) operators use short circuit evaluation, they

are unreliable
can only return Boolean values

can be used in selections to assign values to variables

can only be used in if and switch statements

13) When two expressions connected by the OR operator ( || )


are assigned to a variable, the first expression is assigned to
the variable if
When taking the question, it would appear as:
When two expressions connected by the OR operator ( || ) are assigned to a variable, the first
expression is assigned to the variable if
Question options:
the first expression isn’t null or undefined
the first expression is null or undefined
the second expression isn’t null or undefined
the second expression is null or undefined
When grading the question, it would appear as:
When two expressions connected by the OR operator ( || ) are assigned to a variable, the first
expression is assigned to the variable if

the first expression isn’t null or undefined

the first expression is null or undefined


the second expression isn’t null or undefined
the second expression is null or undefined

14) Which line of code below provides a default value for the
variable named selected if the variable named state is null?
When taking the question, it would appear as:
Which line of code below provides a default value for the variable named selected if the
variable named state is null?
Question options:
let selected;

let selected = state ?? "CA";

let selected = state && state.toString();

let selected = state;

When grading the question, it would appear as:


Which line of code below provides a default value for the variable named selected if the
variable named state is null?
let selected;

let selected = state ?? "CA";

let selected = state && state.toString();

let selected = state;

15) If the geolocation property exists, what does the following


code do?let message = "";if (window?.navigator?.geolocation)
{ message = "Using geolocation";} else { message = "Not
using geolocation";}
When taking the question, it would appear as:
If the geolocation property exists, what does the following code do?
let message = "";
if (window?.navigator?.geolocation) {
message = "Using geolocation";
} else {
message = "Not using geolocation";
}
alert(message);

Question options:
It displays “Using geolocation”.
It displays “Not using geolocation”.
It displays an empty string.
It throws an error.
When grading the question, it would appear as:
If the geolocation property exists, what does the following code do?
let message = "";
if (window?.navigator?.geolocation) {
message = "Using geolocation";
} else {
message = "Not using geolocation";
}
alert(message);

It displays “Using geolocation”.

It displays “Not using geolocation”.


It displays an empty string.
It throws an error.

16) When is an exception thrown?


When taking the question, it would appear as:
When is an exception thrown?
Question options:
When a try statement is encountered.
When an Error object is created.
When invalid data is encountered.
When a runtime error occurs.
When grading the question, it would appear as:
When is an exception thrown?

When a try statement is encountered.


When an Error object is created.
When invalid data is encountered.

When a runtime error occurs.

17) Which property of an Error object stores the type of error?


When taking the question, it would appear as:
Which property of an Error object stores the type of error?
Question options:
name
type
value
message
When grading the question, it would appear as:
Which property of an Error object stores the type of error?

name

type
value
message

18) Which of the following is NOT true about a try-catch


statement?
When taking the question, it would appear as:
Which of the following is NOT true about a try-catch statement?
Question options:
The try block contains the code that may throw exceptions.
The catch block contains the code that is run when an exception is thrown.
The finally block contains code that runs whether or not an exception is thrown.
All three blocks are required.
When grading the question, it would appear as:
Which of the following is NOT true about a try-catch statement?

The try block contains the code that may throw exceptions.
The catch block contains the code that is run when an exception is thrown.
The finally block contains code that runs whether or not an exception is thrown.

All three blocks are required.

19) Which of the following are error types in the Error


hierarchy?
When taking the question, it would appear as:
Which of the following are error types in the Error hierarchy?
Question options:
RangeError and CodeError
ReferenceError and SyntaxError
ReferenceError and FileError
TypeError and CodeError
When grading the question, it would appear as:
Which of the following are error types in the Error hierarchy?

RangeError and CodeError

ReferenceError and SyntaxError

ReferenceError and FileError


TypeError and CodeError

20) What happens when an exception is thrown inside a try


block?
When taking the question, it would appear as:
What happens when an exception is thrown inside a try block?
Question options:
The function returns a value of undefined.
The exception is rethrown to the calling function.
An error message is displayed in the browser’s console window.
Control is transferred to the first statement in the catch block.
When grading the question, it would appear as:
What happens when an exception is thrown inside a try block?

The function returns a value of undefined.


The exception is rethrown to the calling function.
An error message is displayed in the browser’s console window.

Control is transferred to the first statement in the catch block.

21) How can you cause a runtime error to occur?


When taking the question, it would appear as:
How can you cause a runtime error to occur?
Question options:
Create a new Error object and use the throw statement to throw it.
Call the error() method of an object.
Include a cause block in your try-catch statement.
Write code that uses the Error object in a catch block.
When grading the question, it would appear as:
How can you cause a runtime error to occur?

Create a new Error object and use the throw statement to throw it.

Call the error() method of an object.


Include a cause block in your try-catch statement.
Write code that uses the Error object in a catch block.

22) What is displayed when the following code executes?


function divide(a, b) { if (b === 0) { throw new
Error("You may not divide by zero."); } else { return a /
b; }} try { &nb
When taking the question, it would appear as:
What is displayed when the following code executes?
function divide(a, b) {
if (b === 0) {
throw new Error("You may not divide by zero.");
} else {
return a / b;
}
}

try {
const result = divide(10, 0);
alert(result);
}
catch(error) {
alert(error.name + " - " + error.message);
};

Question options:
You may not divide by zero.
Error - You may not divide by zero.
0
infinity
When grading the question, it would appear as:
What is displayed when the following code executes?
function divide(a, b) {
if (b === 0) {
throw new Error("You may not divide by zero.");
} else {
return a / b;
}
}

try {
const result = divide(10, 0);
alert(result);
}
catch(error) {
alert(error.name + " - " + error.message);
};

You may not divide by zero.

Error - You may not divide by zero.

0
infinity

23) What object defines a pattern that can be searched for in a


string?
When taking the question, it would appear as:
What object defines a pattern that can be searched for in a string?
Question options:
String
RegExp
Match
Pattern
When grading the question, it would appear as:
What object defines a pattern that can be searched for in a string?

String

RegExp

Match
Pattern
24) Which method of a regular expression searches a string
and returns true if the pattern is found?
When taking the question, it would appear as:
Which method of a regular expression searches a string and returns true if the pattern is
found?
Question options:
test()
match()
find()
search()
When grading the question, it would appear as:
Which method of a regular expression searches a string and returns true if the pattern is
found?

test()

match()
find()
search()

25) Which letter is used to a create a flag for a case-insensitive


regular expression?
When taking the question, it would appear as:
Which letter is used to a create a flag for a case-insensitive regular expression?
Question options:
c
g
i
x
When grading the question, it would appear as:
Which letter is used to a create a flag for a case-insensitive regular expression?

c
g
i

x
26) Which of the following is used in a regular expression
pattern to match the beginning of a string?
When taking the question, it would appear as:
Which of the following is used in a regular expression pattern to match the beginning of a
string?
Question options:
$

When grading the question, it would appear as:


Which of the following is used in a regular expression pattern to match the beginning of a
string?
$

-
27) Which of the following is used in a regular expression
pattern as an escape character?
When taking the question, it would appear as:
Which of the following is used in a regular expression pattern as an escape character?
Question options:
\

When grading the question, it would appear as:


Which of the following is used in a regular expression pattern as an escape character?
\

28) Which of the following patterns can be used to validate a


five digit ZIP code?
When taking the question, it would appear as:
Which of the following patterns can be used to validate a five digit ZIP code?
Question options:
/[d5]/

/+\d[5]?/

/^\d{5}$/

/$\d5^/

When grading the question, it would appear as:


Which of the following patterns can be used to validate a five digit ZIP code?
/[d5]/

/+\d[5]?/

/^\d{5}$/

/$\d5^/

29) Which of the strings matches the following


pattern?/^[01]?\d\/[0-3]\d\/\d{4}$/
When taking the question, it would appear as:
Which of the strings matches the following pattern?
/^[01]?\d\/[0-3]\d\/\d{4}$/

Question options:
"2/4/68"

"2-4-1968"

"02/04/68"

"2/4/1968"
When grading the question, it would appear as:
Which of the strings matches the following pattern?
/^[01]?\d\/[0-3]\d\/\d{4}$/

"2/4/68"

"2-4-1968"

"02/04/68"

"2/4/1968"

30) The following code displaysconst text = "A111-B222-


C333";if (/^\d{4}-\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid1");} else if (/^\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid2");} else if (/^\w\d{3}-\w\d{3}-\w\
d{3}$/.test(text)) { alert("Valid3&
When taking the question, it would appear as:
The following code displays
const text = "A111-B222-C333";
if (/^\d{4}-\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid1");
} else if (/^\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid2");
} else if (/^\w\d{3}-\w\d{3}-\w\d{3}$/.test(text)) {
alert("Valid3");
} else {
alert("NOT Valid");
}

Question options:
Valid1
Valid2
Valid3
NOT Valid
When grading the question, it would appear as:
The following code displays
const text = "A111-B222-C333";
if (/^\d{4}-\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid1");
} else if (/^\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid2");
} else if (/^\w\d{3}-\w\d{3}-\w\d{3}$/.test(text)) {
alert("Valid3");
} else {
alert("NOT Valid");
}
Valid1
Valid2

Valid3

NOT Valid

Preview Question Pool Questions - Chapter 10 Questions

1) What does an HTML5 type attribute for an input element


do?
When taking the question, it would appear as:
What does an HTML5 type attribute for an input element do?
Question options:
It validates the data entered by the user.
It indicates the type of data the user should enter in the control.
It indicates the type of control the browser should display to the user.
It makes working with CSS easier.
When grading the question, it would appear as:
What does an HTML5 type attribute for an input element do?

It validates the data entered by the user.

It indicates the type of data the user should enter in the control.

It indicates the type of control the browser should display to the user.
It makes working with CSS easier.

2) What does an input element with a type attribute of “email”


provide that an input element with a type of “text” doesn’t
provide?
When taking the question, it would appear as:
What does an input element with a type attribute of “email” provide that an input element
with a type of “text” doesn’t provide?
Question options:
Supports the autofocus attribute.
Supports the placeholder attribute.
Causes the field to be automatically validated by the browser.
Provides for autocompletion.
When grading the question, it would appear as:
What does an input element with a type attribute of “email” provide that an input element
with a type of “text” doesn’t provide?

Supports the autofocus attribute.


Supports the placeholder attribute.

Causes the field to be automatically validated by the browser.

Provides for autocompletion.

3) Which of the following HTML5 attributes is used for data


validation?
When taking the question, it would appear as:
Which of the following HTML5 attributes is used for data validation?
Question options:
pattern

autofocus

action

placeholder

When grading the question, it would appear as:


Which of the following HTML5 attributes is used for data validation?

pattern

autofocus

action

placeholder

4) Which of the following can you NOT format using CSS3


pseudo-classes?
When taking the question, it would appear as:
Which of the following can you NOT format using CSS3 pseudo-classes?
Question options:
valid fields
invalid fields
required fields
optional fields
When grading the question, it would appear as:
Which of the following can you NOT format using CSS3 pseudo-classes?

valid fields
invalid fields
required fields

optional fields

5) Which of the following methods removes all the spaces


before and after an entry in a text box?
When taking the question, it would appear as:
Which of the following methods removes all the spaces before and after an entry in a text
box?
Question options:
val()
trim()
text()
select()
When grading the question, it would appear as:
Which of the following methods removes all the spaces before and after an entry in a text
box?

val()

trim()

text()
select()
6) Which of the following is NOT a jQuery selector for
working with forms and controls?
When taking the question, it would appear as:
Which of the following is NOT a jQuery selector for working with forms and controls?
Question options:
:hidden
:disabled
:text
:submit
When grading the question, it would appear as:
Which of the following is NOT a jQuery selector for working with forms and controls?

:hidden

:disabled
:text
:submit

7) The jQuery features for forms and controls let you do all
but one of the following. Which one is it?
When taking the question, it would appear as:
The jQuery features for forms and controls let you do all but one of the following. Which one
is it?
Question options:
set the values of error messages
get the value in a text box
select the check boxes that are checked
validate specific types of entries in text boxes
When grading the question, it would appear as:
The jQuery features for forms and controls let you do all but one of the following. Which one
is it?

set the values of error messages


get the value in a text box
select the check boxes that are checked

validate specific types of entries in text boxes

8) You can use a handler for the submit event of a form to


validate data when the user clicks a
When taking the question, it would appear as:
You can use a handler for the submit event of a form to validate data when the user clicks a
Question options:
regular button
radio button
submit button
link
When grading the question, it would appear as:
You can use a handler for the submit event of a form to validate data when the user clicks a

regular button
radio button

submit button

link

9) Which of the following coding sequences can be used to


validate the data on a form and submit it to the server?
When taking the question, it would appear as:
Which of the following coding sequences can be used to validate the data on a form and
submit it to the server?
Question options:
Within the click() event handler of a regular button, validate the data and then issue the submit() method of
Within the click() event handler of a regular button, validate the data and then issue the reset() method of th
Within the click() event handler of a submit button, validate the data and then issue the preventDefault() me
Within the click() event handler of a submit button, validate the data and then issue the reset() method of th
When grading the question, it would appear as:
Which of the following coding sequences can be used to validate the data on a form and
submit it to the server?

Within the click() event handler of a regular button, validate the data and then issue the
submit() method of the form if the data is valid.
Within the click() event handler of a regular button, validate the data and then issue the
reset() method of the form if the data is invalid.
Within the click() event handler of a submit button, validate the data and then issue the
preventDefault() method of the form if the data is valid.
Within the click() event handler of a submit button, validate the data and then issue the
reset() method of the form if the data is valid.

10) Code example 10-1$(document).ready( () => { $


("#contact_me").change( () => { if ($
("#contact_me").attr("checked")) { $
(":radio").attr("disabled", false);&nb
When taking the question, it would appear as:
Code example 10-1
$(document).ready( () => {
$("#contact_me").change( () => {
if ($("#contact_me").attr("checked")) {
$(":radio").attr("disabled", false);
} else {
$(":radio").attr("disabled", true);
}
});
});

(Refer to code example 10-1) What does this code do?


Question options:
It disables or enables a specific radio button when an element is checked or unchecked.
It disables or enables all radio buttons when an element is checked or unchecked.
It disables or enables a specific check box when an element is checked or unchecked.
It disables or enables all check boxes when an element is checked or unchecked.
When grading the question, it would appear as:
Code example 10-1
$(document).ready( () => {
$("#contact_me").change( () => {
if ($("#contact_me").attr("checked")) {
$(":radio").attr("disabled", false);
} else {
$(":radio").attr("disabled", true);
}
});
});

(Refer to code example 10-1) What does this code do?

It disables or enables a specific radio button when an element is checked or unchecked.

It disables or enables all radio buttons when an element is checked or unchecked.

It disables or enables a specific check box when an element is checked or unchecked.


It disables or enables all check boxes when an element is checked or unchecked.

11) Code example 10-1$(document).ready( () => { $


("#contact_me").change( () => { if ($
("#contact_me").attr("checked")) { $
(":radio").attr("disabled", false);&nb
When taking the question, it would appear as:
Code example 10-1
$(document).ready( () => {
$("#contact_me").change( () => {
if ($("#contact_me").attr("checked")) {
$(":radio").attr("disabled", false);
} else {
$(":radio").attr("disabled", true);
}
});
});

(Refer to code example 10-1) What do the jQuery selectors in this code select?
Question options:
an individual element by id only
all radio buttons only
an individual element by id and all radio buttons
an individual element by id and disabled radio buttons
When grading the question, it would appear as:
Code example 10-1
$(document).ready( () => {
$("#contact_me").change( () => {
if ($("#contact_me").attr("checked")) {
$(":radio").attr("disabled", false);
} else {
$(":radio").attr("disabled", true);
}
});
});

(Refer to code example 10-1) What do the jQuery selectors in this code select?

an individual element by id only


all radio buttons only

an individual element by id and all radio buttons

an individual element by id and disabled radio buttons

12) Code example 10-2$(document).ready( () => { $


("#member_form").submit( event => { let isValid =
true; ... const password = $
("#password").val().trim(); &nb
When taking the question, it would appear as:
Code example 10-2
$(document).ready( () => {
$("#member_form").submit( event => {
let isValid = true;
...
const password = $("#password").val().trim();
if (password == "") {
$("#password").next().text("This field is required.");
isValid = false;
} else if ( password.length < 6) {
$("#password").next().text("Must be 6 or more characters.");
isValid = false;
} else {
$("#password").next().text("");
}
$("#password").val(password);
...
if (isValid == false) {
event.preventDefault();
}
});
});

(Refer to code example 10-2) What does the preventDefault() method in this code do?
Question options:
It cancels the change event of the form.
It cancels the submit event of the form.
It triggers the change event of the form.
It triggers the submit event of the form.
When grading the question, it would appear as:
Code example 10-2
$(document).ready( () => {
$("#member_form").submit( event => {
let isValid = true;
...
const password = $("#password").val().trim();
if (password == "") {
$("#password").next().text("This field is required.");
isValid = false;
} else if ( password.length < 6) {
$("#password").next().text("Must be 6 or more characters.");
isValid = false;
} else {
$("#password").next().text("");
}
$("#password").val(password);
...
if (isValid == false) {
event.preventDefault();
}
});
});

(Refer to code example 10-2) What does the preventDefault() method in this code do?

It cancels the change event of the form.

It cancels the submit event of the form.

It triggers the change event of the form.


It triggers the submit event of the form.

13) Code example 10-2$(document).ready( () => { $


("#member_form").submit( event => { let isValid =
true; ... const password = $
("#password").val().trim(); &nb
When taking the question, it would appear as:
Code example 10-2
$(document).ready( () => {
$("#member_form").submit( event => {
let isValid = true;
...
const password = $("#password").val().trim();
if (password == "") {
$("#password").next().text("This field is required.");
isValid = false;
} else if ( password.length < 6) {
$("#password").next().text("Must be 6 or more characters.");
isValid = false;
} else {
$("#password").next().text("");
}
$("#password").val(password);
...
if (isValid == false) {
event.preventDefault();
}
});
});

(Refer to code example 10-2) Why is the following line of code necessary after the if-else
statement?
$("#password").val(password);

Question options:
The val() method removes the password entered by the user, so this code displays the original password.
The next() method replaces the password entered by the user, so this code displays the original password.
The text() method replaces the password entered by the user, so this code displays the original password.
The trim() method removes extra spaces entered by the user, so this code displays the trimmed password.
When grading the question, it would appear as:
Code example 10-2
$(document).ready( () => {
$("#member_form").submit( event => {
let isValid = true;
...
const password = $("#password").val().trim();
if (password == "") {
$("#password").next().text("This field is required.");
isValid = false;
} else if ( password.length < 6) {
$("#password").next().text("Must be 6 or more characters.");
isValid = false;
} else {
$("#password").next().text("");
}
$("#password").val(password);
...
if (isValid == false) {
event.preventDefault();
}
});
});
(Refer to code example 10-2) Why is the following line of code necessary after the if-else
statement?
$("#password").val(password);

The val() method removes the password entered by the user, so this code displays the
original password.
The next() method replaces the password entered by the user, so this code displays the
original password.
The text() method replaces the password entered by the user, so this code displays the
original password.
The trim() method removes extra spaces entered by the user, so this code displays the
trimmed password.

14) Which of the following methods is NOT one of the


methods that trigger events?
When taking the question, it would appear as:
Which of the following methods is NOT one of the methods that trigger events?
Question options:
focus()
change()
leave()
select()
When grading the question, it would appear as:
Which of the following methods is NOT one of the methods that trigger events?

focus()
change()

leave()

select()

15) In the following code, what does the line of code in the
else clause do?$(document).ready( () => { $
("#join_list").click( () => { // join_list is a regular button
if ( $("email_address").val() == "") { &nbsp
When taking the question, it would appear as:
In the following code, what does the line of code in the else clause do?
$(document).ready( () => {
$("#join_list").click( () => { // join_list is a regular button
if ( $("email_address").val() == "") {
alert("Please enter an email address.");
} else {
$("#email_form").submit();
}
});
});

Question options:
It handles the submit event of the form with an id of “email_form”.
It triggers the submit event of the form with an id of “email_form”.
It handles the click event of the button with an id of “join_list”.
It triggers the click event of the button with an id of “join_list”.
When grading the question, it would appear as:
In the following code, what does the line of code in the else clause do?
$(document).ready( () => {
$("#join_list").click( () => { // join_list is a regular button
if ( $("email_address").val() == "") {
alert("Please enter an email address.");
} else {
$("#email_form").submit();
}
});
});

It handles the submit event of the form with an id of “email_form”.

It triggers the submit event of the form with an id of “email_form”.

It handles the click event of the button with an id of “join_list”.


It triggers the click event of the button with an id of “join_list”.

Preview Question Pool Questions - Chapter 12 Questions

1) Which property of the Number object returns the largest


positive value that JavaScript can represent?
When taking the question, it would appear as:
Which property of the Number object returns the largest positive value that JavaScript can
represent?
Question options:
MIN_VALUE
MAX_VALUE
POSITIVE_INFINITY
NEGATIVE_INFINITY
When grading the question, it would appear as:
Which property of the Number object returns the largest positive value that JavaScript can
represent?

MIN_VALUE

MAX_VALUE

POSITIVE_INFINITY
NEGATIVE_INFINITY

2) If a numerical operation returns a number greater than the


largest possible JavaScript value, it returns
When taking the question, it would appear as:
If a numerical operation returns a number greater than the largest possible JavaScript value, it
returns
Question options:
NaN
-NaN
Infinity
-Infinity
When grading the question, it would appear as:
If a numerical operation returns a number greater than the largest possible JavaScript value, it
returns

NaN
-NaN

Infinity

-Infinity

3) In JavaScript, NaN represents


When taking the question, it would appear as:
In JavaScript, NaN represents
Question options:
a value that is not a number
the largest positive value that can be represented
the smallest positive value that can be represented
infinity
When grading the question, it would appear as:
In JavaScript, NaN represents

a value that is not a number

the largest positive value that can be represented


the smallest positive value that can be represented
infinity

4) What method of the Number object returns the string for a


number with base 10 as the default?
When taking the question, it would appear as:
What method of the Number object returns the string for a number with base 10 as the
default?
Question options:
the toString() method
the round() method
the toPrecision() method
the toFixed() method
When grading the question, it would appear as:
What method of the Number object returns the string for a number with base 10 as the
default?

the toString() method

the round() method


the toPrecision() method
the toFixed() method
5) What method of the Number object returns a string with the
number rounded to the specified number of decimal places?
When taking the question, it would appear as:
What method of the Number object returns a string with the number rounded to the specified
number of decimal places?
Question options:
the toString() method
the round() method
the toPrecision() method
the toFixed() method
When grading the question, it would appear as:
What method of the Number object returns a string with the number rounded to the specified
number of decimal places?

the toString() method


the round() method
the toPrecision() method

the toFixed() method

6) What method of the Math object can be used to return the


largest value from the values that are passed to it?
When taking the question, it would appear as:
What method of the Math object can be used to return the largest value from the values that
are passed to it?
Question options:
the Math.max() method
the Math.ceil() method
the Math.pow() method
the Math.abs() method
When grading the question, it would appear as:
What method of the Math object can be used to return the largest value from the values that
are passed to it?
the Math.max() method

the Math.ceil() method


the Math.pow() method
the Math.abs() method

7) What method of the Math object can be used to generate


and return a decimal number that’s greater than or equal to 0
but less than 1?
When taking the question, it would appear as:
What method of the Math object can be used to generate and return a decimal number that’s
greater than or equal to 0 but less than 1?
Question options:
the Math.round() method
the Math.random() method
the Math.floor() method
the Math.sqrt() method
When grading the question, it would appear as:
What method of the Math object can be used to generate and return a decimal number that’s
greater than or equal to 0 but less than 1?

the Math.round() method

the Math.random() method

the Math.floor() method


the Math.sqrt() method

8) The length property of the String object returns


When taking the question, it would appear as:
The length property of the String object returns
Question options:
the number of words in the string
the index of the first character in the string
the index of the last character in the string
the number of characters in the string
When grading the question, it would appear as:
The length property of the String object returns

the number of words in the string


the index of the first character in the string
the index of the last character in the string

the number of characters in the string

9) What method of the String object searches the string for an


occurence of the specified search string?
When taking the question, it would appear as:
What method of the String object searches the string for an occurence of the specified search
string?
Question options:
the charAt() method
the search() method
the indexOf() method
the substring() method
When grading the question, it would appear as:
What method of the String object searches the string for an occurence of the specified search
string?

the charAt() method


the search() method

the indexOf() method

the substring() method

10) What method of the String object removes whitespace


from the beginning and the end of the string?
When taking the question, it would appear as:
What method of the String object removes whitespace from the beginning and the end of the
string?
Question options:
the pad() method
the padStart() method
the trim() method
the trimStart() method
When grading the question, it would appear as:
What method of the String object removes whitespace from the beginning and the end of the
string?

the pad() method


the padStart() method

the trim() method

the trimStart() method

11) Which of the following statements is NOT a valid way to


create a Date object named birthday?
When taking the question, it would appear as:
Which of the following statements is NOT a valid way to create a Date object named
birthday?
Question options:
const birthday = "12/2/1978";

const birthday = new Date();

const birthday = new Date("12/2/1978");

const birthday = new Date(1978, 12, 2);

When grading the question, it would appear as:


Which of the following statements is NOT a valid way to create a Date object named
birthday?

const birthday = "12/2/1978";

const birthday = new Date();

const birthday = new Date("12/2/1978");

const birthday = new Date(1978, 12, 2);

12) What method of the Date object gets the day of the month?
When taking the question, it would appear as:
What method of the Date object gets the day of the month?
Question options:
the getMonth() method
the getDate() method
the getDay() method
the getDayOfMonth() method
When grading the question, it would appear as:
What method of the Date object gets the day of the month?

the getMonth() method

the getDate() method

the getDay() method


the getDayOfMonth() method

13) What does the getMonth() method of the Date object


return?
When taking the question, it would appear as:
What does the getMonth() method of the Date object return?
Question options:
An integer value for the month, starting with 1 for January, 2 for February, etc.
An integer value for the month, starting with 0 for January, 1 for February, etc.
A string value for the short month name.
A string value for the full month name.
When grading the question, it would appear as:
What does the getMonth() method of the Date object return?

An integer value for the month, starting with 1 for January, 2 for February, etc.

An integer value for the month, starting with 0 for January, 1 for February, etc.

A string value for the short month name.


A string value for the full month name.
14) What is the value of salesTax after the following code
executes?let salesTax = 53.937;salesTax =
parseFloat(salesTax.toFixed(2));
When taking the question, it would appear as:
What is the value of salesTax after the following code executes?
let salesTax = 53.937;
salesTax = parseFloat(salesTax.toFixed(2));

Question options:
NaN
53.937
53.94
53.93
When grading the question, it would appear as:
What is the value of salesTax after the following code executes?
let salesTax = 53.937;
salesTax = parseFloat(salesTax.toFixed(2));

NaN
53.937

53.94

53.93

15) Which of the following statements performs a case-


insensitive comparison of the strings named text1 and text2?
When taking the question, it would appear as:
Which of the following statements performs a case-insensitive comparison of the strings
named text1 and text2?
Question options:
text1 = text2

text1 == text2

text1.toLowerCase() = text2.toLowerCase()

text1.toLowerCase() == text2.toLowerCase()

When grading the question, it would appear as:


Which of the following statements performs a case-insensitive comparison of the strings
named text1 and text2?
text1 = text2

text1 == text2

text1.toLowerCase() = text2.toLowerCase()

text1.toLowerCase() == text2.toLowerCase()

16) Given a Date object named due_date, which of the


following statements sets the month to February?
When taking the question, it would appear as:
Given a Date object named due_date, which of the following statements sets the month to
February?
Question options:
due_date.setMonth(1);

due_date.setMonth(2);

due_date.setMonth("Feb");

due_date.setMonth("February");

When grading the question, it would appear as:


Given a Date object named due_date, which of the following statements sets the month to
February?

due_date.setMonth(1);

due_date.setMonth(2);

due_date.setMonth("Feb");

due_date.setMonth("February");

17) What text does the following code display in the dialog
box?const investment = "$100";if (isNaN(investment) ||
investment <= 0) { alert("Investment is not valid.");} else
{ alert("Investment: " + investment.toFixed(2));
When taking the question, it would appear as:
What text does the following code display in the dialog box?
const investment = "$100";
if (isNaN(investment) || investment <= 0) {
alert("Investment is not valid.");
} else {
alert("Investment: " + investment.toFixed(2));
}

Question options:
Investment is not valid.
Investment: $100
Investment: $100.00
Investment: 100.00
When grading the question, it would appear as:
What text does the following code display in the dialog box?
const investment = "$100";
if (isNaN(investment) || investment <= 0) {
alert("Investment is not valid.");
} else {
alert("Investment: " + investment.toFixed(2));
}

Investment is not valid.

Investment: $100
Investment: $100.00
Investment: 100.00

18) What is the value of random after the following code


executes?let random = Math.floor(Math.random() * 10);
When taking the question, it would appear as:
What is the value of random after the following code executes?
let random = Math.floor(Math.random() * 10);

Question options:
An integer between 0 and 9
An integer between 0 and 10
An integer between 1 and 9
An integer between 1 and 10
When grading the question, it would appear as:
What is the value of random after the following code executes?
let random = Math.floor(Math.random() * 10);

An integer between 0 and 9

An integer between 0 and 10


An integer between 1 and 9
An integer between 1 and 10

19) Which of the following statements adds 21 days to the


date in the dueDate variable below?let dueDate = new Date();
When taking the question, it would appear as:
Which of the following statements adds 21 days to the date in the dueDate variable below?
let dueDate = new Date();

Question options:
dueDate = dueDate + 21;

dueDate = dueDate.getDate() + 21;

dueDate.setDate(21);

dueDate.setDate(dueDate.getDate() + 21);

When grading the question, it would appear as:


Which of the following statements adds 21 days to the date in the dueDate variable below?
let dueDate = new Date();

dueDate = dueDate + 21;

dueDate = dueDate.getDate() + 21;

dueDate.setDate(21);

dueDate.setDate(dueDate.getDate() + 21);

20) How can you calculate the number of days between the
dates in the two variables below?let taxDay = new
Date("4/15/2017");let xmas = new Date("12/25/2017");
When taking the question, it would appear as:
How can you calculate the number of days between the dates in the two variables below?
let taxDay = new Date("4/15/2017");
let xmas = new Date("12/25/2017");

Question options:
Subtract taxDay.getDate() from xmas.getDate().
Subtract taxDay.getDay() from xmas.getDay().
Subtract taxDay.getTime() from xmas.getTime() and divide by 86400000 to convert milliseconds to days.
Subtract taxDay from xmas.
When grading the question, it would appear as:
How can you calculate the number of days between the dates in the two variables below?
let taxDay = new Date("4/15/2017");
let xmas = new Date("12/25/2017");

Subtract taxDay.getDate() from xmas.getDate().


Subtract taxDay.getDay() from xmas.getDay().
Subtract taxDay.getTime() from xmas.getTime() and divide by 86400000 to convert
milliseconds to days.
Subtract taxDay from xmas.
21) Which of the following creates a constant named totalStr
that contains a string of “$10,720.40”?const total = 10720.40;
When taking the question, it would appear as:
Which of the following creates a constant named totalStr that contains a string of
“$10,720.40”?
const total = 10720.40;

Question options:
const us = new Intl.NumberFormat("en-US");
const totalStr = us.format(total);
const us = new Intl.NumberFormat("en-US",
{style:"currency", currency:"USD"});
const totalStr = us.format(total);
const us = new Intl.NumberFormat("en-EUR");
const totalStr = us.format(total);

const totalStr = `$${total.toFixed(2)}`;

When grading the question, it would appear as:


Which of the following creates a constant named totalStr that contains a string of
“$10,720.40”?
const total = 10720.40;

const us = new Intl.NumberFormat("en-US");


const totalStr = us.format(total);
const us = new Intl.NumberFormat("en-US",
{style:"currency", currency:"USD"});
const totalStr = us.format(total);
const us = new Intl.NumberFormat("en-EUR");
const totalStr = us.format(total);
const totalStr = `$${total.toFixed(2)}`;

Preview Question Pool Questions - Chapter 13 Questions


1) Which of the following operators does NOT perform type
coercion?
When taking the question, it would appear as:
Which of the following operators does NOT perform type coercion?
Question options:
>
===
>=
!=
When grading the question, it would appear as:
Which of the following operators does NOT perform type coercion?

>

===

>=
!=

2) What are the values of the two variables when the following
code executes?let result1 = (1 == "1");let result2 = (1 ===
"1");
When taking the question, it would appear as:
What are the values of the two variables when the following code executes?
let result1 = (1 == "1");
let result2 = (1 === "1");

Question options:
both variables are true
both variables are false
result1 is false and result2 is true
result1 is true and result2 is false
When grading the question, it would appear as:
What are the values of the two variables when the following code executes?
let result1 = (1 == "1");
let result2 = (1 === "1");

both variables are true


both variables are false
result1 is false and result2 is true

result1 is true and result2 is false

3) What is the difference between the break statement and the


continue statement in a loop?
When taking the question, it would appear as:
What is the difference between the break statement and the continue statement in a loop?
Question options:
The break statement ends a loop.
The continue statement ends the current iteration of a loop.
The continue statement ends a loop.
The break statement ends the current iteration of a loop.
The break statement is used in for loops.
The continue statement is used in while loops.
There is no difference.
When grading the question, it would appear as:
What is the difference between the break statement and the continue statement in a loop?

The break statement ends a loop.


The continue statement ends the current iteration of a loop.
The continue statement ends a loop.
The break statement ends the current iteration of a loop.
The break statement is used in for loops.
The continue statement is used in while loops.
There is no difference.

4) What is displayed when the following code executes?let


numbers = "";for (let i = 1; i <= 30; i++) { if( i % 2 === 0 )
{ continue; } else { numbers += i + " "; } }
When taking the question, it would appear as:
What is displayed when the following code executes?
let numbers = "";
for (let i = 1; i <= 30; i++) {
if( i % 2 === 0 ) {
continue;
} else {
numbers += i + " ";
}
}
alert(numbers);

Question options:
even numbers from 2 to 30
odd numbers from 1 to 29
an empty string
the number 1
When grading the question, it would appear as:
What is displayed when the following code executes?
let numbers = "";
for (let i = 1; i <= 30; i++) {
if( i % 2 === 0 ) {
continue;
} else {
numbers += i + " ";
}
}
alert(numbers);

even numbers from 2 to 30

odd numbers from 1 to 29

an empty string
the number 1

5) You can use a switch statement in place of an if statement


with multiple else if clauses
When taking the question, it would appear as:
You can use a switch statement in place of an if statement with multiple else if clauses
Question options:
any time
as long as the switch statement contains a default case
when several expressions are tested for equality with multiple values
when one expression is tested for equality with multiple values
When grading the question, it would appear as:
You can use a switch statement in place of an if statement with multiple else if clauses

any time
as long as the switch statement contains a default case
when several expressions are tested for equality with multiple values

when one expression is tested for equality with multiple values

6) If a case label of a switch statement doesn’t contain a break


statement, what will the code execution do?
When taking the question, it would appear as:
If a case label of a switch statement doesn’t contain a break statement, what will the code
execution do?
Question options:
Stop
Fall through to the default label
Fall through to the next label
Throw an error
When grading the question, it would appear as:
If a case label of a switch statement doesn’t contain a break statement, what will the code
execution do?

Stop
Fall through to the default label

Fall through to the next label

Throw an error
7) What is displayed when the following code executes?const
statusCode = "403";switch (statusCode) { case "200":
alert("OK"); break; case "403": &nbs
When taking the question, it would appear as:
What is displayed when the following code executes?
const statusCode = "403";
switch (statusCode) {
case "200":
alert("OK");
break;
case "403":
alert("Forbidden");
break;
case "404":
alert("Not Found");
break;
default:
alert("Unknown Status");
break;
}

Question options:
OK
Forbidden
Not Found
Unknown Status
When grading the question, it would appear as:
What is displayed when the following code executes?
const statusCode = "403";
switch (statusCode) {
case "200":
alert("OK");
break;
case "403":
alert("Forbidden");
break;
case "404":
alert("Not Found");
break;
default:
alert("Unknown Status");
break;
}

OK

Forbidden

Not Found
Unknown Status

8) Which of the following statements about the conditional


operator is NOT true?
When taking the question, it would appear as:
Which of the following statements about the conditional operator is NOT true?
Question options:
If the first operand is true, it returns the second operand.
If the first operand is false, it returns the third operand.
The third operand is optional.
It can be rewritten as an if statement.
When grading the question, it would appear as:
Which of the following statements about the conditional operator is NOT true?

If the first operand is true, it returns the second operand.


If the first operand is false, it returns the third operand.

The third operand is optional.

It can be rewritten as an if statement.

9) What is the value of the variable named highest after the


following code executes?let number = 20;let highest =
18;highest = (number > highest) ? number : highest;
When taking the question, it would appear as:
What is the value of the variable named highest after the following code executes?
let number = 20;
let highest = 18;
highest = (number > highest) ? number : highest;

Question options:
true

20

18

undefined

When grading the question, it would appear as:


What is the value of the variable named highest after the following code executes?
let number = 20;
let highest = 18;
highest = (number > highest) ? number : highest;

true

20

18

undefined

10) Which of the following conditional expressions evaluate to


true?
When taking the question, it would appear as:
Which of the following conditional expressions evaluate to true?
Question options:
(0)

("Mike")

("")

(null)

When grading the question, it would appear as:


Which of the following conditional expressions evaluate to true?
(0)

("Mike")

("")

(null)

11) What does the following code display?let country = "";let


valid = "";if (country) { valid = "Valid";} else { valid =
"Not valid";}alert(valid);
When taking the question, it would appear as:
What does the following code display?
let country = "";
let valid = "";
if (country) {
valid = "Valid";
} else {
valid = "Not valid";
}
alert(valid);

Question options:
false
Valid
Not valid
empty string
When grading the question, it would appear as:
What does the following code display?
let country = "";
let valid = "";
if (country) {
valid = "Valid";
} else {
valid = "Not valid";
}
alert(valid);

false
Valid

Not valid

empty string

12) Because the AND ( && ) and OR ( || ) operators use short


circuit evaluation, they
When taking the question, it would appear as:
Because the AND ( && ) and OR ( || ) operators use short circuit evaluation, they
Question options:
are unreliable
can only return Boolean values
can be used in selections to assign values to variables
can only be used in if and switch statements
When grading the question, it would appear as:
Because the AND ( && ) and OR ( || ) operators use short circuit evaluation, they

are unreliable
can only return Boolean values

can be used in selections to assign values to variables

can only be used in if and switch statements

13) When two expressions connected by the OR operator ( || )


are assigned to a variable, the first expression is assigned to
the variable if
When taking the question, it would appear as:
When two expressions connected by the OR operator ( || ) are assigned to a variable, the first
expression is assigned to the variable if
Question options:
the first expression isn’t null or undefined
the first expression is null or undefined
the second expression isn’t null or undefined
the second expression is null or undefined
When grading the question, it would appear as:
When two expressions connected by the OR operator ( || ) are assigned to a variable, the first
expression is assigned to the variable if

the first expression isn’t null or undefined

the first expression is null or undefined


the second expression isn’t null or undefined
the second expression is null or undefined

14) Which line of code below provides a default value for the
variable named selected if the variable named state is null?
When taking the question, it would appear as:
Which line of code below provides a default value for the variable named selected if the
variable named state is null?
Question options:
let selected;

let selected = state ?? "CA";

let selected = state && state.toString();

let selected = state;

When grading the question, it would appear as:


Which line of code below provides a default value for the variable named selected if the
variable named state is null?
let selected;

let selected = state ?? "CA";

let selected = state && state.toString();

let selected = state;

15) If the geolocation property exists, what does the following


code do?let message = "";if (window?.navigator?.geolocation)
{ message = "Using geolocation";} else { message = "Not
using geolocation";}
When taking the question, it would appear as:
If the geolocation property exists, what does the following code do?
let message = "";
if (window?.navigator?.geolocation) {
message = "Using geolocation";
} else {
message = "Not using geolocation";
}
alert(message);

Question options:
It displays “Using geolocation”.
It displays “Not using geolocation”.
It displays an empty string.
It throws an error.
When grading the question, it would appear as:
If the geolocation property exists, what does the following code do?
let message = "";
if (window?.navigator?.geolocation) {
message = "Using geolocation";
} else {
message = "Not using geolocation";
}
alert(message);

It displays “Using geolocation”.

It displays “Not using geolocation”.


It displays an empty string.
It throws an error.

16) When is an exception thrown?


When taking the question, it would appear as:
When is an exception thrown?
Question options:
When a try statement is encountered.
When an Error object is created.
When invalid data is encountered.
When a runtime error occurs.
When grading the question, it would appear as:
When is an exception thrown?

When a try statement is encountered.


When an Error object is created.
When invalid data is encountered.

When a runtime error occurs.

17) Which property of an Error object stores the type of error?


When taking the question, it would appear as:
Which property of an Error object stores the type of error?
Question options:
name
type
value
message
When grading the question, it would appear as:
Which property of an Error object stores the type of error?

name

type
value
message

18) Which of the following is NOT true about a try-catch


statement?
When taking the question, it would appear as:
Which of the following is NOT true about a try-catch statement?
Question options:
The try block contains the code that may throw exceptions.
The catch block contains the code that is run when an exception is thrown.
The finally block contains code that runs whether or not an exception is thrown.
All three blocks are required.
When grading the question, it would appear as:
Which of the following is NOT true about a try-catch statement?

The try block contains the code that may throw exceptions.
The catch block contains the code that is run when an exception is thrown.
The finally block contains code that runs whether or not an exception is thrown.

All three blocks are required.

19) Which of the following are error types in the Error


hierarchy?
When taking the question, it would appear as:
Which of the following are error types in the Error hierarchy?
Question options:
RangeError and CodeError
ReferenceError and SyntaxError
ReferenceError and FileError
TypeError and CodeError
When grading the question, it would appear as:
Which of the following are error types in the Error hierarchy?

RangeError and CodeError

ReferenceError and SyntaxError

ReferenceError and FileError


TypeError and CodeError

20) What happens when an exception is thrown inside a try


block?
When taking the question, it would appear as:
What happens when an exception is thrown inside a try block?
Question options:
The function returns a value of undefined.
The exception is rethrown to the calling function.
An error message is displayed in the browser’s console window.
Control is transferred to the first statement in the catch block.
When grading the question, it would appear as:
What happens when an exception is thrown inside a try block?

The function returns a value of undefined.


The exception is rethrown to the calling function.
An error message is displayed in the browser’s console window.

Control is transferred to the first statement in the catch block.

21) How can you cause a runtime error to occur?


When taking the question, it would appear as:
How can you cause a runtime error to occur?
Question options:
Create a new Error object and use the throw statement to throw it.
Call the error() method of an object.
Include a cause block in your try-catch statement.
Write code that uses the Error object in a catch block.
When grading the question, it would appear as:
How can you cause a runtime error to occur?

Create a new Error object and use the throw statement to throw it.

Call the error() method of an object.


Include a cause block in your try-catch statement.
Write code that uses the Error object in a catch block.

22) What is displayed when the following code executes?


function divide(a, b) { if (b === 0) { throw new
Error("You may not divide by zero."); } else { return a /
b; }} try { &nb
When taking the question, it would appear as:
What is displayed when the following code executes?
function divide(a, b) {
if (b === 0) {
throw new Error("You may not divide by zero.");
} else {
return a / b;
}
}

try {
const result = divide(10, 0);
alert(result);
}
catch(error) {
alert(error.name + " - " + error.message);
};

Question options:
You may not divide by zero.
Error - You may not divide by zero.
0
infinity
When grading the question, it would appear as:
What is displayed when the following code executes?
function divide(a, b) {
if (b === 0) {
throw new Error("You may not divide by zero.");
} else {
return a / b;
}
}

try {
const result = divide(10, 0);
alert(result);
}
catch(error) {
alert(error.name + " - " + error.message);
};

You may not divide by zero.

Error - You may not divide by zero.

0
infinity

23) What object defines a pattern that can be searched for in a


string?
When taking the question, it would appear as:
What object defines a pattern that can be searched for in a string?
Question options:
String
RegExp
Match
Pattern
When grading the question, it would appear as:
What object defines a pattern that can be searched for in a string?

String

RegExp

Match
Pattern

24) Which method of a regular expression searches a string


and returns true if the pattern is found?
When taking the question, it would appear as:
Which method of a regular expression searches a string and returns true if the pattern is
found?
Question options:
test()
match()
find()
search()
When grading the question, it would appear as:
Which method of a regular expression searches a string and returns true if the pattern is
found?

test()

match()
find()
search()
25) Which letter is used to a create a flag for a case-insensitive
regular expression?
When taking the question, it would appear as:
Which letter is used to a create a flag for a case-insensitive regular expression?
Question options:
c
g
i
x
When grading the question, it would appear as:
Which letter is used to a create a flag for a case-insensitive regular expression?

c
g

26) Which of the following is used in a regular expression


pattern to match the beginning of a string?
When taking the question, it would appear as:
Which of the following is used in a regular expression pattern to match the beginning of a
string?
Question options:
$

When grading the question, it would appear as:


Which of the following is used in a regular expression pattern to match the beginning of a
string?
$

?
*

27) Which of the following is used in a regular expression


pattern as an escape character?
When taking the question, it would appear as:
Which of the following is used in a regular expression pattern as an escape character?
Question options:
\

When grading the question, it would appear as:


Which of the following is used in a regular expression pattern as an escape character?

28) Which of the following patterns can be used to validate a


five digit ZIP code?
When taking the question, it would appear as:
Which of the following patterns can be used to validate a five digit ZIP code?
Question options:
/[d5]/

/+\d[5]?/

/^\d{5}$/

/$\d5^/

When grading the question, it would appear as:


Which of the following patterns can be used to validate a five digit ZIP code?
/[d5]/

/+\d[5]?/

/^\d{5}$/

/$\d5^/

29) Which of the strings matches the following


pattern?/^[01]?\d\/[0-3]\d\/\d{4}$/
When taking the question, it would appear as:
Which of the strings matches the following pattern?
/^[01]?\d\/[0-3]\d\/\d{4}$/

Question options:
"2/4/68"

"2-4-1968"

"02/04/68"

"2/4/1968"

When grading the question, it would appear as:


Which of the strings matches the following pattern?
/^[01]?\d\/[0-3]\d\/\d{4}$/

"2/4/68"

"2-4-1968"

"02/04/68"

"2/4/1968"

30) The following code displaysconst text = "A111-B222-


C333";if (/^\d{4}-\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid1");} else if (/^\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid2");} else if (/^\w\d{3}-\w\d{3}-\w\
d{3}$/.test(text)) { alert("Valid3&
When taking the question, it would appear as:
The following code displays
const text = "A111-B222-C333";
if (/^\d{4}-\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid1");
} else if (/^\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid2");
} else if (/^\w\d{3}-\w\d{3}-\w\d{3}$/.test(text)) {
alert("Valid3");
} else {
alert("NOT Valid");
}

Question options:
Valid1
Valid2
Valid3
NOT Valid
When grading the question, it would appear as:
The following code displays
const text = "A111-B222-C333";
if (/^\d{4}-\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid1");
} else if (/^\d{4}-\d{4}-\d{4}$/.test(text)) {
alert("Valid2");
} else if (/^\w\d{3}-\w\d{3}-\w\d{3}$/.test(text)) {
alert("Valid3");
} else {
alert("NOT Valid");
}

Valid1
Valid2

Valid3

NOT Valid

Preview Question Pool Questions - Chapter 14 Questions

1) Which property of the location object can be used to


retrieve the query string from the URL?
When taking the question, it would appear as:
Which property of the location object can be used to retrieve the query string from the URL?
Question options:
search
query
params
options
When grading the question, it would appear as:
Which property of the location object can be used to retrieve the query string from the URL?

search

query
params
options

2) Which property of the location object can be used to


retrieve the complete URL?
When taking the question, it would appear as:
Which property of the location object can be used to retrieve the complete URL?
Question options:
path
host
hostname
href
When grading the question, it would appear as:
Which property of the location object can be used to retrieve the complete URL?

path
host
hostname

href

3) The reload() method of the location object has an optional


force parameter. If it’s set to true, the browser
When taking the question, it would appear as:
The reload() method of the location object has an optional force parameter. If it’s set to true,
the browser
Question options:
loads the page from the client
loads the page from cache memory
loads the page from the server
doesn’t reload the page
When grading the question, it would appear as:
The reload() method of the location object has an optional force parameter. If it’s set to true,
the browser

loads the page from the client


loads the page from cache memory

loads the page from the server

doesn’t reload the page

4) Which of the following statements loads a new page and


overwrites the current history page?
When taking the question, it would appear as:
Which of the following statements loads a new page and overwrites the current history page?
Question options:
location.reload();

location.replace("https://wwww.murach.com");

history.replace("https://wwww.murach.com");

history.go("https://wwww.murach.com");

When grading the question, it would appear as:


Which of the following statements loads a new page and overwrites the current history page?
location.reload();

location.replace("https://wwww.murach.com");

history.replace("https://wwww.murach.com");

history.go("https://wwww.murach.com");

5) Which of the following is NOT a method of the history


object?
When taking the question, it would appear as:
Which of the following is NOT a method of the history object?
Question options:
replace()
back()
forward()
go()
When grading the question, it would appear as:
Which of the following is NOT a method of the history object?

replace()

back()
forward()
go()

6) Which of the following statements goes back one step in the


URL history?
When taking the question, it would appear as:
Which of the following statements goes back one step in the URL history?
Question options:
history.length = -1;

history.go(1);

history.back();

history.go("back");

When grading the question, it would appear as:


Which of the following statements goes back one step in the URL history?
history.length = -1;

history.go(1);

history.back();

history.go("back");

7) Session cookies
When taking the question, it would appear as:
Session cookies
Question options:
must not have a path
are deleted when the browser is closed
are always encrypted when sent to the web server
are stored on the hard drive
When grading the question, it would appear as:
Session cookies

must not have a path

are deleted when the browser is closed

are always encrypted when sent to the web server


are stored on the hard drive

8) Which attribute of a cookie do you set to create a persistent


cookie?
When taking the question, it would appear as:
Which attribute of a cookie do you set to create a persistent cookie?
Question options:
max-age
path
domain
secure
When grading the question, it would appear as:
Which attribute of a cookie do you set to create a persistent cookie?

max-age

path
domain
secure
9) The max-age attribute of a cookie is specified in
When taking the question, it would appear as:
The max-age attribute of a cookie is specified in
Question options:
days
hours
seconds
milliseconds
When grading the question, it would appear as:
The max-age attribute of a cookie is specified in

days
hours

seconds

milliseconds

10) Which of the following is allowed in a cookie’s value?


When taking the question, it would appear as:
Which of the following is allowed in a cookie’s value?
Question options:
a space
a number
a comma
a semicolon
When grading the question, it would appear as:
Which of the following is allowed in a cookie’s value?

a space

a number

a comma
a semicolon
11) Code example 14-1let cookie =
"username=mike2009";cookie += "; max-age=" + 365 * 24 *
60 * 60;cookie += "; path=/";document.cookie = cookie;
(Refer to code example 14-1.) This code
When taking the question, it would appear as:
Code example 14-1
let cookie = "username=mike2009";
cookie += "; max-age=" + 365 * 24 * 60 * 60;
cookie += "; path=/";
document.cookie = cookie;

(Refer to code example 14-1.) This code


Question options:
creates a cookie that’s removed when the user closes the browser
creates a cookie that’s stored for 1 year
creates a cookie that’s stored for 365 minutes
does not create a cookie
When grading the question, it would appear as:
Code example 14-1
let cookie = "username=mike2009";
cookie += "; max-age=" + 365 * 24 * 60 * 60;
cookie += "; path=/";
document.cookie = cookie;

(Refer to code example 14-1.) This code

creates a cookie that’s removed when the user closes the browser

creates a cookie that’s stored for 1 year

creates a cookie that’s stored for 365 minutes


does not create a cookie

12) Code example 14-1let cookie =


"username=mike2009";cookie += "; max-age=" + 365 * 24 *
60 * 60;cookie += "; path=/";document.cookie = cookie;
(Refer to code example 14-1.) This code
When taking the question, it would appear as:
Code example 14-1
let cookie = "username=mike2009";
cookie += "; max-age=" + 365 * 24 * 60 * 60;
cookie += "; path=/";
document.cookie = cookie;

(Refer to code example 14-1.) This code


Question options:
creates a cookie with a name of “username” and a value of “mike2009”
creates a cookie with a name of “max-age” and a value of “31536000”.
creates a cookie with a name of “path” and a value of “/”.
does not create a cookie
When grading the question, it would appear as:
Code example 14-1
let cookie = "username=mike2009";
cookie += "; max-age=" + 365 * 24 * 60 * 60;
cookie += "; path=/";
document.cookie = cookie;

(Refer to code example 14-1.) This code

creates a cookie with a name of “username” and a value of “mike2009”

creates a cookie with a name of “max-age” and a value of “31536000”.


creates a cookie with a name of “path” and a value of “/”.
does not create a cookie

13) Web storage stores data in the browser in


When taking the question, it would appear as:
Web storage stores data in the browser in
Question options:
arrays
strings
key/value pairs
session
When grading the question, it would appear as:
Web storage stores data in the browser in

arrays
strings

key/value pairs

session

14) Which of the following statements is NOT true of web


storage?
When taking the question, it would appear as:
Which of the following statements is NOT true of web storage?
Question options:
It can store up to 5MB of data.
It’s supported by every modern browser.
You can store data indefinitely or for the browser session.
The data in web storage is passed to the server with every HTTP request.
When grading the question, it would appear as:
Which of the following statements is NOT true of web storage?

It can store up to 5MB of data.


It’s supported by every modern browser.
You can store data indefinitely or for the browser session.

The data in web storage is passed to the server with every HTTP request.

15) The main difference between local storage and session


storage is
When taking the question, it would appear as:
The main difference between local storage and session storage is
Question options:
session storage is lost when the browser closes; local storage is stored indefinitely
session storage is stored indefinitely; local storage is lost when the browser closes
session storage has a shortcut syntax and local storage doesn’t
local storage has a clear() method and session storage doesn’t
When grading the question, it would appear as:
The main difference between local storage and session storage is

session storage is lost when the browser closes; local storage is stored indefinitely

session storage is stored indefinitely; local storage is lost when the browser closes
session storage has a shortcut syntax and local storage doesn’t
local storage has a clear() method and session storage doesn’t

16) Which of the following statements gets the same result as


this statement?localStorage.name = "Grace";
When taking the question, it would appear as:
Which of the following statements gets the same result as this statement?
localStorage.name = "Grace";

Question options:
localStorage.setItem("name", "Grace");

localStorage.getItem("name", "Grace");

localStorage.save("name", "Grace");

localStorage.clear("name", "Grace");

When grading the question, it would appear as:


Which of the following statements gets the same result as this statement?
localStorage.name = "Grace";

localStorage.setItem("name", "Grace");

localStorage.getItem("name", "Grace");

localStorage.save("name", "Grace");

localStorage.clear("name", "Grace");

17) Which of the following statements stores an item in the


browser indefinitely?
When taking the question, it would appear as:
Which of the following statements stores an item in the browser indefinitely?
Question options:
sessionStorage.favoriteTeam = "Seahawks";

sessionStorage.save(favoriteTeam, "Seahawks");

localStorage.favoriteTeam = "Seahawks";

localStorage.save(favoriteTeam, "Seahawks");

When grading the question, it would appear as:


Which of the following statements stores an item in the browser indefinitely?
sessionStorage.favoriteTeam = "Seahawks";

sessionStorage.save(favoriteTeam, "Seahawks");

localStorage.favoriteTeam = "Seahawks";

localStorage.save(favoriteTeam, "Seahawks");

Preview Question Pool Questions - Chapter 15 Questions

1) The index value of the first element in a JavaScript array is


When taking the question, it would appear as:
The index value of the first element in a JavaScript array is
Question options:
null

undefined

When grading the question, it would appear as:


The index value of the first element in a JavaScript array is
null

1
undefined

2) What does the length property of an array return?


When taking the question, it would appear as:
What does the length property of an array return?
Question options:
the number of elements in the array
the number of strings in the array
the contents of the array
the number of elements in the array that aren’t undefined
When grading the question, it would appear as:
What does the length property of an array return?

the number of elements in the array

the number of strings in the array


the contents of the array
the number of elements in the array that aren’t undefined

3) The delete operator deletes


When taking the question, it would appear as:
The delete operator deletes
Question options:
an array
an element in an array
the contents of an element in an array
undefined elements in an array
When grading the question, it would appear as:
The delete operator deletes

an array
an element in an array

the contents of an element in an array


undefined elements in an array

4) Which of the following statements about for and for-in


loops is true?
When taking the question, it would appear as:
Which of the following statements about for and for-in loops is true?
Question options:
Both for and for-in loops process undefined elements.
Both for and for-in loops skip over undefined elements.
A for-in loop processes undefined elements, but a for loop skips over them.
A for loop processes undefined elements, but a for-in loop skips over them.
When grading the question, it would appear as:
Which of the following statements about for and for-in loops is true?

Both for and for-in loops process undefined elements.


Both for and for-in loops skip over undefined elements.
A for-in loop processes undefined elements, but a for loop skips over them.

A for loop processes undefined elements, but a for-in loop skips over them.

5) What does the following code display?const pets = ["Dog",


"Cat", undefined, "Bird"];let message = ""for (const pet of
pets) { message += pet + "|";}alert(message);
When taking the question, it would appear as:
What does the following code display?
const pets = ["Dog", "Cat", undefined, "Bird"];
let message = ""
for (const pet of pets) {
message += pet + "|";
}
alert(message);

Question options:
0|1|2|3|

0|1|undefined|3|

Dog|Cat|Bird|

Dog|Cat|undefined|Bird|
When grading the question, it would appear as:
What does the following code display?
const pets = ["Dog", "Cat", undefined, "Bird"];
let message = ""
for (const pet of pets) {
message += pet + "|";
}
alert(message);

0|1|2|3|

0|1|undefined|3|

Dog|Cat|Bird|

Dog|Cat|undefined|Bird|

6) What does the following code display?const pets = ["Dog",


"Cat", undefined, "Bird"];const [pet1, pet2] = pets;alert(pet2);
When taking the question, it would appear as:
What does the following code display?
const pets = ["Dog", "Cat", undefined, "Bird"];
const [pet1, pet2] = pets;
alert(pet2);

Question options:
Dog

Cat

undefined

Bird

When grading the question, it would appear as:


What does the following code display?
const pets = ["Dog", "Cat", undefined, "Bird"];
const [pet1, pet2] = pets;
alert(pet2);

Dog

Cat

undefined

Bird
7) Which method adds one or more elements to the beginning
of an array?
When taking the question, it would appear as:
Which method adds one or more elements to the beginning of an array?
Question options:
shift()
unshift()
push()
pop()
When grading the question, it would appear as:
Which method adds one or more elements to the beginning of an array?

shift()

unshift()

push()
pop()

8) Which method removes the last element from the end of an


array?
When taking the question, it would appear as:
Which method removes the last element from the end of an array?
Question options:
shift()
unshift()
push()
pop()
When grading the question, it would appear as:
Which method removes the last element from the end of an array?

shift()
unshift()
push()
pop()
9) Which method returns the elements of an array in a string
where each element is separated by a comma?
When taking the question, it would appear as:
Which method returns the elements of an array in a string where each element is separated by
a comma?
Question options:
join()
concat()
splice()
shift()
When grading the question, it would appear as:
Which method returns the elements of an array in a string where each element is separated by
a comma?

join()

concat()
splice()
shift()

10) Which method accepts a function that combines all the


elements in the array and then returns the resulting value?
When taking the question, it would appear as:
Which method accepts a function that combines all the elements in the array and then returns
the resulting value?
Question options:
reduce()
forEach()
map()
filter()
When grading the question, it would appear as:
Which method accepts a function that combines all the elements in the array and then returns
the resulting value?

reduce()

forEach()
map()
filter()

11) Which method accepts a function that is executed once for


each element and returns a new array that contains the
elements that meet the condition specified in the function?
When taking the question, it would appear as:
Which method accepts a function that is executed once for each element and returns a new
array that contains the elements that meet the condition specified in the function?
Question options:
reduce()
forEach()
map()
filter()
When grading the question, it would appear as:
Which method accepts a function that is executed once for each element and returns a new
array that contains the elements that meet the condition specified in the function?

reduce()
forEach()
map()

filter()

12) Which of the following statements about the sort() method


of an array is NOT true?
When taking the question, it would appear as:
Which of the following statements about the sort() method of an array is NOT true?
Question options:
It sorts in ascending alphanumeric sequence by default.
You can change the sort criteria of the method by passing it a function.
The function passed to the sort() method compares two values.
The function passed to the sort() method returns a value of true or false.
When grading the question, it would appear as:
Which of the following statements about the sort() method of an array is NOT true?

It sorts in ascending alphanumeric sequence by default.


You can change the sort criteria of the method by passing it a function.
The function passed to the sort() method compares two values.

The function passed to the sort() method returns a value of true or false.

13) What does the following code display?const date =


"2/4/68";const dateParts =
date.split("/");console.log(dateParts.length);
When taking the question, it would appear as:
What does the following code display?
const date = "2/4/68";
const dateParts = date.split("/");
console.log(dateParts.length);

Question options:
1
2
3
68
When grading the question, it would appear as:
What does the following code display?
const date = "2/4/68";
const dateParts = date.split("/");
console.log(dateParts.length);

1
2

68
14) What does the optional limit parameter of the split()
method do?
When taking the question, it would appear as:
What does the optional limit parameter of the split() method do?
Question options:
It limits the type of values the new array can contain.
It specifies the maximum number of elements in the new array.
It limits the values that the separator parameter can accept.
It specifies the order of the elements in the new array.
When grading the question, it would appear as:
What does the optional limit parameter of the split() method do?

It limits the type of values the new array can contain.

It specifies the maximum number of elements in the new array.

It limits the values that the separator parameter can accept.


It specifies the order of the elements in the new array.

15) Which of the following statements makes a copy of an


array named pets?
When taking the question, it would appear as:
Which of the following statements makes a copy of an array named pets?
Question options:
const petsCopy = pets;

const petsCopy = pets.copy();

const petsCopy = Array.copy(pets);

const petsCopy = pets.slice();

When grading the question, it would appear as:


Which of the following statements makes a copy of an array named pets?
const petsCopy = pets;

const petsCopy = pets.copy();

const petsCopy = Array.copy(pets);


const petsCopy = pets.slice();

16) Which of the following statements about associative arrays


is true?
When taking the question, it would appear as:
Which of the following statements about associative arrays is true?
Question options:
An associative array doesn’t have a length property.
An associative array uses strings as the indexes.
The for-in loop won’t work with an associative array.
You can’t delete elements from an associative array.
When grading the question, it would appear as:
Which of the following statements about associative arrays is true?

An associative array doesn’t have a length property.

An associative array uses strings as the indexes.

The for-in loop won’t work with an associative array.


You can’t delete elements from an associative array.

17) Which of the following statements about an array of arrays


is true?
When taking the question, it would appear as:
Which of the following statements about an array of arrays is true?
Question options:
Two indexes are used to access a value that’s stored in an array of arrays.
An associative array can’t be used as an array within another array.
Arrays can only be nested two deep. In other words, you can’t have an array of arrays of arrays.
An array of arrays must store a one-dimensional list of values.
When grading the question, it would appear as:
Which of the following statements about an array of arrays is true?

Two indexes are used to access a value that’s stored in an array of arrays.
An associative array can’t be used as an array within another array.
Arrays can only be nested two deep. In other words, you can’t have an array of arrays of
arrays.
An array of arrays must store a one-dimensional list of values.

18) What will the value of the totalsString variable be after the
following code is executed?const totals = [141.95, 212.95,
326.21, 491.95];totals[2] = 529.21;let totalsString = "";for
(const i in totals) { totalsString += i.toString() + "=" +
totals[i] + "|";}</
When taking the question, it would appear as:
What will the value of the totalsString variable be after the following code is executed?
const totals = [141.95, 212.95, 326.21, 491.95];
totals[2] = 529.21;
let totalsString = "";
for (const i in totals) {
totalsString += i.toString() + "=" + totals[i] + "|";
}
alert(totalsString);

Question options:
0=141.95|1=529.21|2=326.21|3=491.95|

0=141.95|1=212.95|2=529.21|3=491.95|

1=141.95|2=529.21|3=326.21|4=491.95|

1=141.95|2=212.95|3=529.21|4=491.95|

When grading the question, it would appear as:


What will the value of the totalsString variable be after the following code is executed?
const totals = [141.95, 212.95, 326.21, 491.95];
totals[2] = 529.21;
let totalsString = "";
for (const i in totals) {
totalsString += i.toString() + "=" + totals[i] + "|";
}
alert(totalsString);

0=141.95|1=529.21|2=326.21|3=491.95|

0=141.95|1=212.95|2=529.21|3=491.95|

1=141.95|2=529.21|3=326.21|4=491.95|

1=141.95|2=212.95|3=529.21|4=491.95|
19) What does the second statement that follows do?let
numbers = [1, 2, 3, 4];numbers.length = 0;
When taking the question, it would appear as:
What does the second statement that follows do?
let numbers = [1, 2, 3, 4];
numbers.length = 0;

Question options:
Nothing.
Removes all the elements in the array.
Sets all the elements in the array to undefined.
Only changes the value of the length property.
When grading the question, it would appear as:
What does the second statement that follows do?
let numbers = [1, 2, 3, 4];
numbers.length = 0;

Nothing.

Removes all the elements in the array.

Sets all the elements in the array to undefined.


Only changes the value of the length property.

20) After the following code runs, what string is stored in the
variable named message?const answers = ["C", "B", "D",
"A"];delete answers[3];let message = "";for (const i in
answers) { message += answers[i];
When taking the question, it would appear as:
After the following code runs, what string is stored in the variable named message?
const answers = ["C", "B", "D", "A"];
delete answers[3];
let message = "";
for (const i in answers) {
message += answers[i];
}

Question options:
C
CBDundefined
CBA
CBD
When grading the question, it would appear as:
After the following code runs, what string is stored in the variable named message?
const answers = ["C", "B", "D", "A"];
delete answers[3];
let message = "";
for (const i in answers) {
message += answers[i];
}

C
CBDundefined
CBA

CBD

21) After the following code runs, what string it stored in the
variable named message?const answers = ["C", "B", "D",
"A"];delete answers[3];let message = "";for (const answer of
answers) { message += answer;
When taking the question, it would appear as:
After the following code runs, what string it stored in the variable named message?
const answers = ["C", "B", "D", "A"];
delete answers[3];
let message = "";
for (const answer of answers) {
message += answer;
}

Question options:
C
CBDundefined
CBA
CBD
When grading the question, it would appear as:
After the following code runs, what string it stored in the variable named message?
const answers = ["C", "B", "D", "A"];
delete answers[3];
let message = "";
for (const answer of answers) {
message += answer;
}
C

CBDundefined

CBA
CBD

22) Given the following code, which of the following


statements displays “John Smith is 29”?const employee =
[];employee["name"] = "John Smith";employee["age"] = 29;
When taking the question, it would appear as:
Given the following code, which of the following statements displays “John Smith is 29”?
const employee = [];
employee["name"] = "John Smith";
employee["age"] = 29;

Question options:
alert(employee[0] + " is " + employee[1]);

alert(employee[1] + " is " + employee[2]);

alert(employee["name"] + " is " + employee["age"]);

alert(employee["name"][0] + " is " + employee["age"][0]);

When grading the question, it would appear as:


Given the following code, which of the following statements displays “John Smith is 29”?
const employee = [];
employee["name"] = "John Smith";
employee["age"] = 29;

alert(employee[0] + " is " + employee[1]);

alert(employee[1] + " is " + employee[2]);

alert(employee["name"] + " is " + employee["age"]);

alert(employee["name"][0] + " is " + employee["age"][0]);

23) Code example 15-1const testScores = [];testScores[0] =


[80, 82, 90, 87, 85];testScores[1] = [79, 80, 74, 82,
81];testScores[2] = [93, 95, 89, 100, 85];testScores[3] = [60,
72, 65, 71, 79];
When taking the question, it would appear as:
Code example 15-1
const testScores = [];
testScores[0] = [80, 82, 90, 87, 85];
testScores[1] = [79, 80, 74, 82, 81];
testScores[2] = [93, 95, 89, 100, 85];
testScores[3] = [60, 72, 65, 71, 79];

(Refer to code example 15-1) This code creates a tabular structure that has
Question options:
5 rows and 5 columns
4 rows and 4 columns
4 rows and 5 columns
3 rows and 5 columns
When grading the question, it would appear as:
Code example 15-1
const testScores = [];
testScores[0] = [80, 82, 90, 87, 85];
testScores[1] = [79, 80, 74, 82, 81];
testScores[2] = [93, 95, 89, 100, 85];
testScores[3] = [60, 72, 65, 71, 79];

(Refer to code example 15-1) This code creates a tabular structure that has

5 rows and 5 columns


4 rows and 4 columns

4 rows and 5 columns

3 rows and 5 columns


24) Code example 15-1const testScores = [];testScores[0] =
[80, 82, 90, 87, 85];testScores[1] = [79, 80, 74, 82,
81];testScores[2] = [93, 95, 89, 100, 85];testScores[3] = [60,
72, 65, 71, 79];
When taking the question, it would appear as:
Code example 15-1
const testScores = [];
testScores[0] = [80, 82, 90, 87, 85];
testScores[1] = [79, 80, 74, 82, 81];
testScores[2] = [93, 95, 89, 100, 85];
testScores[3] = [60, 72, 65, 71, 79];
(Refer to code example 15-1) Which of the following returns a value of 89?
Question options:
testScores[0][4]

testScores[1][3]

testScores[2][2]

testScores[3][1]

When grading the question, it would appear as:


Code example 15-1
const testScores = [];
testScores[0] = [80, 82, 90, 87, 85];
testScores[1] = [79, 80, 74, 82, 81];
testScores[2] = [93, 95, 89, 100, 85];
testScores[3] = [60, 72, 65, 71, 79];

(Refer to code example 15-1) Which of the following returns a value of 89?
testScores[0][4]

testScores[1][3]

testScores[2][2]

testScores[3][1]

25) Which of the following statements about JSON is true?


When taking the question, it would appear as:
Which of the following statements about JSON is true?
Question options:
JSON can only be used to store Array objects, not other objects such as Date objects.
JSON uses a binary format to store and transmit the data for an object.
JSON can only be used with JavaScript, not other languages such as PHP.
JSON uses text to store and transmit the data for an object such as an Array object.
When grading the question, it would appear as:
Which of the following statements about JSON is true?

JSON can only be used to store Array objects, not other objects such as Date objects.
JSON uses a binary format to store and transmit the data for an object.
JSON can only be used with JavaScript, not other languages such as PHP.

JSON uses text to store and transmit the data for an object such as an Array object.

26) Which of the following statements converts the following


array to a JSON string?const instruments = ["Guitar", "Bass",
"Drums"];
When taking the question, it would appear as:
Which of the following statements converts the following array to a JSON string?
const instruments = ["Guitar", "Bass", "Drums"];

Question options:
const json = JSON.toString(instruments);

const json = JSON.convert(instruments);

const json = JSON.parse(instruments);

const json = JSON.stringify(instruments);

When grading the question, it would appear as:


Which of the following statements converts the following array to a JSON string?
const instruments = ["Guitar", "Bass", "Drums"];

const json = JSON.toString(instruments);

const json = JSON.convert(instruments);

const json = JSON.parse(instruments);

const json = JSON.stringify(instruments);

27) Which of the following statements converts a JSON string


named json to an array of instruments?
When taking the question, it would appear as:
Which of the following statements converts a JSON string named json to an array of
instruments?
Question options:
const instrArray = JSON.fromString(json);

const instrArray = JSON.convert(json);

const instrArray = JSON.parse(json);


const instrArray = JSON.stringify(json);

When grading the question, it would appear as:


Which of the following statements converts a JSON string named json to an array of
instruments?
const instrArray = JSON.fromString(json);

const instrArray = JSON.convert(json);

const instrArray = JSON.parse(json);

const instrArray = JSON.stringify(json);

28) After the following code executes, what values are stored
in the set named idsSet?const ids = [1, 2, 3, 2, 4];const idsSet
= new Set(ids);
When taking the question, it would appear as:
After the following code executes, what values are stored in the set named idsSet?
const ids = [1, 2, 3, 2, 4];
const idsSet = new Set(ids);

Question options:
1, 2, 3

1, 3, 4

1, 2, 3, 4

1, 2, 3, 2, 4

When grading the question, it would appear as:


After the following code executes, what values are stored in the set named idsSet?
const ids = [1, 2, 3, 2, 4];
const idsSet = new Set(ids);

1, 2, 3

1, 3, 4

1, 2, 3, 4

1, 2, 3, 2, 4

29) What does the following code display on the console?


const employeeMap = new
Map();employeeMap.set("mary@murach.com", "Mary
Wigginton");const name = "Mary Delamater";const email =
"mary@murach.com";if (employeeMap.has(email)) {
console.log(employeeMap.get(email))}else {
When taking the question, it would appear as:
What does the following code display on the console?
const employeeMap = new Map();
employeeMap.set("mary@murach.com", "Mary Wigginton");

const name = "Mary Delamater";


const email = "mary@murach.com";
if (employeeMap.has(email)) {
console.log(employeeMap.get(email))
}
else {
employeeMap.set(email, name);
console.log(name + " has been added.")
}

Question options:
mary@murach.com

Mary Wigginton

Mary Delamater

Mary Delamater has been added

When grading the question, it would appear as:


What does the following code display on the console?
const employeeMap = new Map();
employeeMap.set("mary@murach.com", "Mary Wigginton");

const name = "Mary Delamater";


const email = "mary@murach.com";
if (employeeMap.has(email)) {
console.log(employeeMap.get(email))
}
else {
employeeMap.set(email, name);
console.log(name + " has been added.")
}

mary@murach.com

Mary Wigginton

Mary Delamater

Mary Delamater has been added


Preview Question Pool Questions - Chapter 16 Questions

1) Code example 16-1const invoice = { taxRate: 0.0875,


getSalesTax(subtotal) { return subtotal * this.taxRate;
}, getTotal(subtotal) { return subtotal +
this.getSalesTax(subt
When taking the question, it would appear as:
Code example 16-1
const invoice = {
taxRate: 0.0875,
getSalesTax(subtotal) {
return subtotal * this.taxRate;
},
getTotal(subtotal) {
return subtotal + this.getSalesTax(subtotal);
}
};

(Refer to code example 16-1) This code creates an object with


Question options:
1 property and 2 methods
3 properties
3 methods
2 properties and 1 method
When grading the question, it would appear as:
Code example 16-1
const invoice = {
taxRate: 0.0875,
getSalesTax(subtotal) {
return subtotal * this.taxRate;
},
getTotal(subtotal) {
return subtotal + this.getSalesTax(subtotal);
}
};
(Refer to code example 16-1) This code creates an object with

1 property and 2 methods

3 properties
3 methods
2 properties and 1 method

2) Code example 16-1const invoice = { taxRate: 0.0875,


getSalesTax(subtotal) { return subtotal * this.taxRate;
}, getTotal(subtotal) { return subtotal +
this.getSalesTax(subt
When taking the question, it would appear as:
Code example 16-1
const invoice = {
taxRate: 0.0875,
getSalesTax(subtotal) {
return subtotal * this.taxRate;
},
getTotal(subtotal) {
return subtotal + this.getSalesTax(subtotal);
}
};

(Refer to code example 16-1) Given the following constant for the subtotal of an invoice,
which of the following statements gets the total for invoice?
const subtotal = 100;

Question options:
const total = getTotal(subtotal);

const total = invoice.getTotal();

const total = invoice.getTotal() + getSalesTax();

const total = invoice.getTotal(subtotal);

When grading the question, it would appear as:


Code example 16-1
const invoice = {
taxRate: 0.0875,
getSalesTax(subtotal) {
return subtotal * this.taxRate;
},
getTotal(subtotal) {
return subtotal + this.getSalesTax(subtotal);
}
};

(Refer to code example 16-1) Given the following constant for the subtotal of an invoice,
which of the following statements gets the total for invoice?
const subtotal = 100;

const total = getTotal(subtotal);

const total = invoice.getTotal();

const total = invoice.getTotal() + getSalesTax();

const total = invoice.getTotal(subtotal);

3) Code example 16-1const invoice = { taxRate: 0.0875,


getSalesTax(subtotal) { return subtotal * this.taxRate;
}, getTotal(subtotal) { return subtotal +
this.getSalesTax(subt
When taking the question, it would appear as:
Code example 16-1
const invoice = {
taxRate: 0.0875,
getSalesTax(subtotal) {
return subtotal * this.taxRate;
},
getTotal(subtotal) {
return subtotal + this.getSalesTax(subtotal);
}
};

(Refer to code example 16-1) This code uses


Question options:
function expression syntax
traditional method syntax
concise method syntax
property method syntax
When grading the question, it would appear as:
Code example 16-1
const invoice = {
taxRate: 0.0875,
getSalesTax(subtotal) {
return subtotal * this.taxRate;
},
getTotal(subtotal) {
return subtotal + this.getSalesTax(subtotal);
}
};

(Refer to code example 16-1) This code uses

function expression syntax


traditional method syntax

concise method syntax

property method syntax

4) When you use a class to define an object type, which


keyword can you use to create an object from the class?
When taking the question, it would appear as:
When you use a class to define an object type, which keyword can you use to create an object
from the class?
Question options:
let
this
create
new
When grading the question, it would appear as:
When you use a class to define an object type, which keyword can you use to create an object
from the class?

let
this
create

new
5) You can create most of the native object types by assigning
a literal value to a variable or constant. Which native object
type requires you to use the new keyword to create an object?
When taking the question, it would appear as:
You can create most of the native object types by assigning a literal value to a variable or
constant. Which native object type requires you to use the new keyword to create an object?
Question options:
Date
Number
String
Object
When grading the question, it would appear as:
You can create most of the native object types by assigning a literal value to a variable or
constant. Which native object type requires you to use the new keyword to create an object?

Date

Number
String
Object

6) When coding an object literal, the concise method syntax is


shorter than the traditional syntax because you don’t need to
code
When taking the question, it would appear as:
When coding an object literal, the concise method syntax is shorter than the traditional syntax
because you don’t need to code
Question options:
the method’s name
the method’s parameter list
the method’s body
a colon and the function keyword
When grading the question, it would appear as:
When coding an object literal, the concise method syntax is shorter than the traditional syntax
because you don’t need to code

the method’s name


the method’s parameter list
the method’s body

a colon and the function keyword

7) The this keyword in a method of an object usually refers to


When taking the question, it would appear as:
The this keyword in a method of an object usually refers to
Question options:
the method itself
the object itself
the file itself
the window object
When grading the question, it would appear as:
The this keyword in a method of an object usually refers to

the method itself

the object itself

the file itself


the window object

8) Which of the following is a true statement about objects?


When taking the question, it would appear as:
Which of the following is a true statement about objects?
Question options:
A variable holds a reference to an object, not the object itself.
The delete operator removes all references to an object.
An object can only be referred to a specific number of times.
When all references to an object are deleted, the object is still kept in memory.
When grading the question, it would appear as:
Which of the following is a true statement about objects?

A variable holds a reference to an object, not the object itself.

The delete operator removes all references to an object.


An object can only be referred to a specific number of times.
When all references to an object are deleted, the object is still kept in memory.

9) Which of the following statements is true after the code


below is executed?let today = new Date("2017-06-01");let
now = today;today.setFullYear(2018);
When taking the question, it would appear as:
Which of the following statements is true after the code below is executed?
let today = new Date("2017-06-01");
let now = today;
today.setFullYear(2018);

Question options:
The getFullYear() method of both variables returns 2017.
The getFullYear() method of both variables returns 2018.
The getFullYear() method of the today variable returns 2018 and the getFullYear() method of the now varia
The getFullYear() method of both variables returns undefined.
When grading the question, it would appear as:
Which of the following statements is true after the code below is executed?
let today = new Date("2017-06-01");
let now = today;
today.setFullYear(2018);

The getFullYear() method of both variables returns 2017.

The getFullYear() method of both variables returns 2018.

The getFullYear() method of the today variable returns 2018 and the getFullYear()
method of the now variable returns 2017.
The getFullYear() method of both variables returns undefined.

10) Which of the following is a true statement about a data


property?
When taking the question, it would appear as:
Which of the following is a true statement about a data property?
Question options:
You use the get or set keyword to define it
It refers to data that’s stored in another property
It does not store data in memory
It stores a specific item of data in memory
When grading the question, it would appear as:
Which of the following is a true statement about a data property?

You use the get or set keyword to define it


It refers to data that’s stored in another property
It does not store data in memory

It stores a specific item of data in memory

11) An write-only accessor property


When taking the question, it would appear as:
An write-only accessor property
Question options:
Only has a getter
Only has a setter
Has a getter and a setter
Returns data that’s stored in a data property
When grading the question, it would appear as:
An write-only accessor property

Only has a getter

Only has a setter

Has a getter and a setter


Returns data that’s stored in a data property

12) Which keyword can you code before a method to create a


read-only accessor property?
When taking the question, it would appear as:
Which keyword can you code before a method to create a read-only accessor property?
Question options:
new
this
readonly
get
When grading the question, it would appear as:
Which keyword can you code before a method to create a read-only accessor property?

new
this
readonly

get

13) Which of the following is a NOT a benefit of using


JavaScript libraries?
When taking the question, it would appear as:
Which of the following is a NOT a benefit of using JavaScript libraries?
Question options:
They make code easier to maintain and reuse.
They let you group similar functionality in a single file.
They encourage separation of concerns.
They download faster and improve website performance.
When grading the question, it would appear as:
Which of the following is a NOT a benefit of using JavaScript libraries?

They make code easier to maintain and reuse.


They let you group similar functionality in a single file.
They encourage separation of concerns.

They download faster and improve website performance.


14) Why might the script tags for these library files be coded
in this order? <script src="jquery-3.4.1.min.js"></script>
<
When taking the question, it would appear as:
Why might the script tags for these library files be coded in this order?
<script src="jquery-3.4.1.min.js"></script>
<script src="lib_mpg.js"></script>

Question options:
The third party jQuery library should be included before the custom mpg library.
The larger jQuery library should be included before the smaller mpg library.
The mpg library contains code that depends on the jQuery library.
JavaScript files should be included in alphabetical order.
When grading the question, it would appear as:
Why might the script tags for these library files be coded in this order?
<script src="jquery-3.4.1.min.js"></script>
<script src="lib_mpg.js"></script>

The third party jQuery library should be included before the custom mpg library.
The larger jQuery library should be included before the smaller mpg library.

The mpg library contains code that depends on the jQuery library.

JavaScript files should be included in alphabetical order.

15) Code example 16-2class Employee {


constructor(firstName, lastName) { this.firstName =
firstName; this.lastName = lastName; }
getFullName() { return th
When taking the question, it would appear as:
Code example 16-2
class Employee {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

getFullName() {
return this.firstName + " " + this.lastName;
}
}
(Refer to code example 16-2) This code creates an Employee object type that contains
Question options:
2 methods
1 constructor and 1 method
1 constructor and 2 properties
1 constructor, 2 properties, and 1 method
When grading the question, it would appear as:
Code example 16-2
class Employee {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

getFullName() {
return this.firstName + " " + this.lastName;
}
}

(Refer to code example 16-2) This code creates an Employee object type that contains

2 methods
1 constructor and 1 method
1 constructor and 2 properties

1 constructor, 2 properties, and 1 method

16) Code example 16-2class Employee {


constructor(firstName, lastName) { this.firstName =
firstName; this.lastName = lastName; }
getFullName() { return th
When taking the question, it would appear as:
Code example 16-2
class Employee {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

getFullName() {
return this.firstName + " " + this.lastName;
}
}

(Refer to code example 16-2) The following code displays


const employee = new Employee("Grace", "Hopper");
alert(employee.firstName);

Question options:
Grace
Hopper
Grace Hopper
Hopper Grace
When grading the question, it would appear as:
Code example 16-2
class Employee {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

getFullName() {
return this.firstName + " " + this.lastName;
}
}

(Refer to code example 16-2) The following code displays


const employee = new Employee("Grace", "Hopper");
alert(employee.firstName);

Grace

Hopper
Grace Hopper
Hopper Grace

17) Code example 16-2class Employee {


constructor(firstName, lastName) { this.firstName =
firstName; this.lastName = lastName; }
getFullName() { return th
When taking the question, it would appear as:
Code example 16-2
class Employee {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

getFullName() {
return this.firstName + " " + this.lastName;
}
}

(Refer to code example 16-2) The following code displays


const employee = new Employee("Grace", "Hopper");
employee.lastName = "Slick";
alert (employee.getFullName());

Question options:
Hopper
Slick
Grace Slick
Grace Hopper
When grading the question, it would appear as:
Code example 16-2
class Employee {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

getFullName() {
return this.firstName + " " + this.lastName;
}
}

(Refer to code example 16-2) The following code displays


const employee = new Employee("Grace", "Hopper");
employee.lastName = "Slick";
alert (employee.getFullName());

Hopper
Slick

Grace Slick

Grace Hopper
18) Code example 16-2class Employee {
constructor(firstName, lastName) { this.firstName =
firstName; this.lastName = lastName; }
getFullName() { return th
When taking the question, it would appear as:
Code example 16-2
class Employee {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

getFullName() {
return this.firstName + " " + this.lastName;
}
}

(Refer to code example 16-2) Which of the following could be used to convert the
getFullName() method to a read-only property named fullName?
Question options:
fullName {
return this.firstName + " " + this.lastName;
}
fullName => {
return this.firstName + " " + this.lastName;
}
get fullName() {
return this.firstName + " " + this.lastName;
}
set fullName() {
return this.firstName + " " + this.lastName;
}

When grading the question, it would appear as:


Code example 16-2
class Employee {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

getFullName() {
return this.firstName + " " + this.lastName;
}
}
(Refer to code example 16-2) Which of the following could be used to convert the
getFullName() method to a read-only property named fullName?
fullName {
return this.firstName + " " + this.lastName;
}
fullName => {
return this.firstName + " " + this.lastName;
}
get fullName() {
return this.firstName + " " + this.lastName;
}
set fullName() {
return this.firstName + " " + this.lastName;
}

19) Which of the following is a true statement about objects?


When taking the question, it would appear as:
Which of the following is a true statement about objects?
Question options:
The Object type inherits the methods of the String type.
The Number type inherits the methods of the Object type.
The String type inherits the methods of the Array type.
The Object type inherits the methods of the Function type.
When grading the question, it would appear as:
Which of the following is a true statement about objects?

The Object type inherits the methods of the String type.

The Number type inherits the methods of the Object type.

The String type inherits the methods of the Array type.


The Object type inherits the methods of the Function type.

20) To create a subclass that inherits properties and methods


from a superclass, you
When taking the question, it would appear as:
To create a subclass that inherits properties and methods from a superclass, you
Question options:
use the extends keyword to specify the superclass
use the inherits keyword to specify the superclass
add the properties and methods to the prototype object of the superclass
pass the prototype object for the superclass to the constructor of the subclass
When grading the question, it would appear as:
To create a subclass that inherits properties and methods from a superclass, you

use the extends keyword to specify the superclass

use the inherits keyword to specify the superclass


add the properties and methods to the prototype object of the superclass
pass the prototype object for the superclass to the constructor of the subclass

21) Object composition is a technique for


When taking the question, it would appear as:
Object composition is a technique for
Question options:
inheriting another class.
adding new features to an existing class.
combining simple objects into more complex data structures.
defining the properties and methods of a superclass.
When grading the question, it would appear as:
Object composition is a technique for

inheriting another class.


adding new features to an existing class.

combining simple objects into more complex data structures.

defining the properties and methods of a superclass.

22) JavaScript is known as a prototypal language because it


creates new objects by using
When taking the question, it would appear as:
JavaScript is known as a prototypal language because it creates new objects by using
Question options:
object literals that are cloned.
classes that are cloned.
own objects that are cloned.
prototype objects that are cloned.
When grading the question, it would appear as:
JavaScript is known as a prototypal language because it creates new objects by using

object literals that are cloned.


classes that are cloned.
own objects that are cloned.

prototype objects that are cloned.

23) Assume that you have an object named employee that only
has two properties named firstName and lastName. What does
the following code do?employee.streetAddress = "123 Main
Street";
When taking the question, it would appear as:
Assume that you have an object named employee that only has two properties named
firstName and lastName. What does the following code do?
employee.streetAddress = "123 Main Street";

Question options:
It adds a method named streetAddress() to the employee object.
It adds a property named streetAddress to the employee object.
It adds an event named streetAddress to the employee object.
It causes an error because no property named streetAddress exists for the employee object.
When grading the question, it would appear as:
Assume that you have an object named employee that only has two properties named
firstName and lastName. What does the following code do?
employee.streetAddress = "123 Main Street";

It adds a method named streetAddress() to the employee object.

It adds a property named streetAddress to the employee object.

It adds an event named streetAddress to the employee object.


It causes an error because no property named streetAddress exists for the employee
object.

24) What does the following code do?


Date.prototype.toTestString = function() { return "Test";};
When taking the question, it would appear as:
What does the following code do?
Date.prototype.toTestString = function() {
return "Test";
};

Question options:
It adds a method named toTestString() to the prototype object that Date objects are cloned from.
It adds a method named toTestString() to the current Date object but not to other Date objects that are create
It adds a property named toTestString to the prototype object that Date objects are cloned from.
It causes an error because no method named toTestString() exists for the Date object.
When grading the question, it would appear as:
What does the following code do?
Date.prototype.toTestString = function() {
return "Test";
};

It adds a method named toTestString() to the prototype object that Date objects are
cloned from.
It adds a method named toTestString() to the current Date object but not to other Date
objects that are created later.
It adds a property named toTestString to the prototype object that Date objects are
cloned from.
It causes an error because no method named toTestString() exists for the Date object.

25) Which statement does the generator function in taskList


object below make possible?const taskList = { tasks: [],
*[Symbol.iterator]() { for (let task of this.tasks) {
yield task;
When taking the question, it would appear as:
Which statement does the generator function in taskList object below make possible?
const taskList = {
tasks: [],
*[Symbol.iterator]() {
for (let task of this.tasks) {
yield task;
}
}
};

Question options:
for (const task of taskList) {
console.log(task)
}
for (const task of taskList.tasks) {
console.log(task)
}
for (const i in taskList.tasks) {
console.log(taskList.tasks[i])
}
for (let i = 0; i < taskList.tasks.length; i++) {
console.log(taskList.tasks[i])
}

When grading the question, it would appear as:


Which statement does the generator function in taskList object below make possible?
const taskList = {
tasks: [],
*[Symbol.iterator]() {
for (let task of this.tasks) {
yield task;
}
}
};

for (const task of taskList) {


console.log(task)
}
for (const task of taskList.tasks) {
console.log(task)
}
for (const i in taskList.tasks) {
console.log(taskList.tasks[i])
}
for (let i = 0; i < taskList.tasks.length; i++) {
console.log(taskList.tasks[i])
}

26) A cascading method is one that


When taking the question, it would appear as:
A cascading method is one that
Question options:
deletes the object when the method is finished
calls itself
creates a new object and initializes its properties
returns the object referred to by the this keyword
When grading the question, it would appear as:
A cascading method is one that

deletes the object when the method is finished


calls itself
creates a new object and initializes its properties

returns the object referred to by the this keyword

27) A cascading method can be chained with other methods.


This style of coding is sometimes called fluent because
When taking the question, it would appear as:
A cascading method can be chained with other methods. This style of coding is sometimes
called fluent because
Question options:
it reads like a sentence and is easy to understand
you have to be fluent in a coding language to use it
the methods have to be called one at a time
the code that chains the methods is verbose
When grading the question, it would appear as:
A cascading method can be chained with other methods. This style of coding is sometimes
called fluent because

it reads like a sentence and is easy to understand

you have to be fluent in a coding language to use it


the methods have to be called one at a time
the code that chains the methods is verbose

28) Given the following object named person, which statement


uses destructuring to store the value of the firstName and
lastName properties in constants named firstName and
lastName?const person = { firstName: "Grace", lastName:
"Hopper"
When taking the question, it would appear as:
Given the following object named person, which statement uses destructuring to store the
value of the firstName and lastName properties in constants named firstName and lastName?
const person = {
firstName: "Grace",
lastName: "Hopper"
};

Question options:
const firstName = person.firstName;
const lastName = person.lastName;

const firstName, lastName = person;

const {firstName, lastName} = person;

const [firstName, lastName] = person;

When grading the question, it would appear as:


Given the following object named person, which statement uses destructuring to store the
value of the firstName and lastName properties in constants named firstName and lastName?
const person = {
firstName: "Grace",
lastName: "Hopper"
};

const firstName = person.firstName;


const lastName = person.lastName;
const firstName, lastName = person;

const {firstName, lastName} = person;

const [firstName, lastName] = person;

You might also like