1) Which variable declaration format is correct?
- favBand let = “Linkin Park”;
b.let favBand = “Linkin Park”;
- let favBand: “Linkin Park”;
- favBand let: “Linkin Park”;
2) Which declaration is a constant for minimum wage?
- let MIN_WAGE;
- var MIN_WAGE = 10;
c.const MIN_WAGE = 10;
- const MIN_WAGE;
3) What is rainbow’s data type?
let rainbow = [“red”, “orange”, “green”, “purple”];
- Array
- Boolean
- String
- Object
4) x = 4 ** 4is the same as _____.
- x = 44
- x = 4 * 4
- x = 4 + 4 + 4 + 4
- x = 4 * 4 * 4 * 4
5) Which compound assignment operator assigns numbers with 9?
let numbers = 3;
numbers _____ 3;
- +=
- -=
- *=
- /=
6) In JavaScript,5 + “5”evaluates to a _____.
- string
- number
- error
- object
7) IfparseInt()cannot return a number, _____ is returned.
- 0
- isNaN()
- Error
- NaN
8) Which if-else statement correctly conveys the following information?
If age is at least 16, “You can learn to drive.” is output.
- if (age >= 16) {
console.log(“You can learn to drive.”);
}
else {
console.log(“You need to wait a little longer.”);
}
- if (age > 16 = true) {
console.log(“You can learn to drive.”);
}
else {
console.log(“You need to wait a little longer.”);
}
- if (age = 16) {
console.log(“You can learn to drive.”);
}
else {
console.log(“You need to wait a little longer.”);
}
- if (age <= 16) {
console.log(“You can learn to drive.”);
}
else {
console.log(“You need to wait a little longer.”);
}
9) Which statement evaluates to true?
let score = 10;
- score == “score”
- score == “10”
- score === “10”
- score === “score”
10) An example of a falsy value is _____.
- if (“cats”)
- if (“”)
- if (5)
- if (” “)
11) What is output to the console?
num = 5;
console.log(num > 10 ? “Iron Man” : “Hulk”);
- true
- Iron Man
- false
- Hulk
12) What is the last number output by the loop?
i = 5
while (i >= 0) {
console.log(i);
i–;
}
- 0
- 1
- 5
- 6
13) _____ loops never stop executing.
- While
- For
- Do-while
- Infinite
14) Which loop executes once before the condition is tested?
- Infinite
- While
- For
- Do-while
15) What is the correct format for calling the function and using 1 and 2 as arguments?
function multiplyNums(a, b) {
return a * b;
}
- multiplyNums(1);multiplyNums(2);
- function multiplyNums(1, 2);
- call multiplyNums(1, 2);
- multiplyNums(1, 2);
16) Which code snippet uses an anonymous function?
- function subNum(a, b) {
return b – a;
}
- let subNum = function(a, b) {
return b – a;
}
- let subNum(a, b) {
return b – a;
}
- subNum function(a, b) {
return b – a;
}
17) Which return statement is correct if the return value is “I will make an apple and blueberry pie.”?
let fruitPie = function (a, b) {
return _____;
}
fruitPie(“apple”, “blueberry”);
- “I will make an ” + “a” + ” and ” + “b” + ” pie.”
- “I will make an ” + (a, b) + pie.”
- “I will make an ” + a + ” and ” + b + ” pie.”
- “I will make an (a) and (b) pie.”
18) Which array is correctly structured?
- let countries: [“England”, “Brazil”, “Cuba”];
- countries = [England, Brazil, Cuba];
- let countries = [“England”, “Brazil”, “Cuba”];
- countries [“England, Brazil, Cuba”];
19) How does theunshift()method change the following array?
let colors = [“red”, “orange”, “yellow”];
colors.unshift(“blue”);
- Replaces red with blue
- Adds blue to end of array
- Adds blue to beginning of array
- Replaces yellow with blue
20) What does the following code snippet output to the console?
let names = [“Mike”, “Belinda”, “Jonny”, “Sophie”];
for (i = 0; i < names.length; i++) {
console.log(names[i]);
}
- “Mike”,
“Belinda”,
“Jonny”,
“Sophie”
- 0Mike
1Belinda
2Jonny
3Sophie
- Mike
Belinda
Jonny
Sophie
- [“Mike”,
“Belinda”,
“Jonny”,
“Sophie”]
21) Which statement changes the puppy object’s name from Daisy to Darth?
let puppy = {
name: “Daisy”,
breed: “husky”,
color: “black”
};
- puppy = “Darth”;
- name = “Darth”;
- puppy name = “Darth”;
- puppy.name = “Darth”;
22) Which code defines a setter for the breed property, such that assigning toperson1.breedsetsperson1.pet?
let person1 = {
firstName: “Sophie”,
lastName: “Hernandez”,
age: 25,
pet: “”,
_____
};
- set breed(value) {
this.pet = value;
}
- set breed(value) {
this.breed = pet;
}
- set breed(value) {
pet = breed;
}
- set breed(value) {
breed = pet;
}
23) What is output by the following code?
let message = “I choose you!”;
console.log(message.charAt(6));
- e
- o
- s
- e you!
24) What is the final output?
let quote = “Talk and they will listen.”;
quote = quote.replace(“talk”, “Speak”);
quote = quote.replace(“they”, “I”);
quote = quote.replace(“LISTEN”, “be heard”);
- Talk and I will listen.
- Speak and I will listen.
- Talk and I will be heard.
- Speak and I will be heard.
25) What is output to the console?
let myPhrase = “Are you talking to me?”;
console.log(myPhrase.split(“a”));
- [“re you t”, “lking to me?”]
- [“Are”, “talking”]
- [“re you tlking”, “to me?”]
- [“Are you t”, “lking to me?”]
26) What is the date?
let day = new Date(2020, 9, 30);
- Mon Nov 30 2020 03:00:00 GMT-0500 (Eastern Standard Time)
- Sun Aug 30 2020 03:00:00 GMT-0400 (Eastern Daylight Time)
- Wed Sep 30 2020 03:00:00 GMT-0400 (Eastern Daylight Time)
- Fri Oct 30 2020 03:00:00 GMT-0400 (Eastern Daylight Time)
27) Which code segment changes the year to 2021?
let changeYear = new Date (2020, 6, 20);
- changeYear = 2021;
- changeYear.setYear(2021);
- changeYear.setFullYear(2021);
- changeYear = setFullYear(2021);
28) Which method changes 10.2 to 11?
- Math.abs(10.2);
- Math.floor(10.2);
- Math.ceil(10.2);
- Math.round(10.2);
29) What is output forMath.pow(4,4);?
- 4
- 16
- 8
- 256
30) What is output?
function findError() {
try {
let message1 = “No errors here”;
message2;
}
catch (error) {
console.log(“There is an error”);
}
}
findError();
console.log(“Done searching”);
- There is an error
- No errors here
Done searching
- Done searching
- There is an error
Done searching
31) What is missing to complete the following code segment?
let places = {
woods: “Guam”,
beach: “PR”,
mountains: “Switzerland”
};
try {
console.log(places.rainforest);
_____ “There might be an error”;
}
catch (error) {
console.log(error);
}
_____ {
console.log(places);
}
- throw, error
- throw, try
- throw, finally
- finally, try
32) Which error is thrown by this code block?
let num = 13;
console.log(num());
- Error
- InternalError
- RangeError
- TypeError
33) What default object is used when no object prefix is utilized to access a property or call a method (example: alert method)?
- document
- window
- console
- navigator
34) What JavaScript object and method is used to write HTML to the web page?
- document.println()
- document.writeln()
- window.write()
- window.print()
35) How many DOM nodes are created from the paragraph?
<p>Feed the dog.</p>
- None
- One for the p element
- One for the p element and one for the paragraph text
- One for the p element, one for the paragraph text, and one for the whitespace within the paragraph text
36) Which statement changes the Pinterest link to a YouTube link?
<!DOCTYPE html>
<html lang=”en”>
<meta charset=”UTF-8″>
<title>DOM example</title>
<body>
<p>
<a href=”https://pinterest.com/”>Pinterest</a>
</p>
<script>
let para = document.querySelector(“p”);
let link = document.querySelector(“a”);
</script>
</body>
</html>
- para.href = “https://www.youtube.com/”;
- link.href = “https://www.youtube.com/”;
- para.innerHTML = “https://www.youtube.com/”;
- link.innerHTML = “https://www.youtube.com/”;
37) What is the preferred way to register an event handler that allows multiple handlers for the same event?
- myButton.addEventListener(“click”, clickHandler);
- myButton.onclick = clickHandler;
- <button onclick=”clickHandler()”>Click Me</button>
- <button onclick=”clickListener”>Click Me</button>
38) An event that occurs when someone enters their name in an input field is a(n) _____ event.
- click
- load
- input
- submit
39) On a given keypress event, the event object’s _____ property is used to access the object where the keypress event occurred.
- event
- click
- target
- element
40) The _____ is required to cancel the interval:
let timerId = setInterval(repeatMe, 1000);
- clearInterval(repeatMe)
- clearInterval(timerId)
- stopInterval(timerId)
- setTimeout(timerId)
41) What code would be used to call a function called repeat every 3 seconds?
- setTimeout(repeat, 3)
- setInterval(repeat, 3000);
- setInterval(repeat, 3);
- setTimeout(repeat, 3000)
42) How many times isshowMe()called when the following code is executed?
let timerId = setTimeout(showMe, 3000);
function showMe() {
let div1 = document.getElementById(“div1”);
div1.style.display = “block”;
alert(“called”);
let timerId = setTimeout(showMe, 3000);
}
- indefinitely
- 1
- 2
- 3
43) In the following JSON, the datatype associated with friends is _____.
{“friends”: [{ “name”:”Bobby”}, {“name”:”Celia”},{“name”:”Judy”}]}
- string
- object
- array
- char
44) How is the age field accessed after the following is executed:
let obj = JSON.parse(‘{“name”:”Bobby”, “age”:20}’);
- this.age
- age
- obj.age
- obj.name.age
45) What doesstringify()return?
JSON.stringify({“friends”: [{ “name”:”Bobby”}, {“name”:”Celia”},{“name”:”Judy”}]});
- single string
- string array
- JSON object
- undefined
46) A(n) _____ allows older browsers to function with newer features by providing missing functionality.
- trifill
- backfill
- polyfill
- altfill
47) A polyfill is engineered to:
- Use JavaScript to implement a feature whenever possible
- Replace HTML to implement a feature after checking if a feature exists
- Use JavaScript to implement a feature after checking if a feature exists
- Use Ajax to implement a feature whenever possible
48) The _____ website shows what features are supported by major browsers and frequency of use.
- W3C
- Tiobe
- CanIUse
- W3Schools
49) Which strings match the regex?
let words = [“dapper”, “paper”, “cat”, “flack”];
let re = /pa|ac/;
- dapper, paper
- paper, flack
- flack, cat
- dapper, flack
50) Which regular expression matches only the words burp, dirt, and right?
let randomWords = [“burp”, “try”, “dirt”, “right”];
- let re = /[a-i]/
- let re = /[e-i]/
- let re = /[i-u]/
- let re = /[r]/
51) Which string inwordNumsmatches the regex?
let wordNums = [“blahblah!!”, “yea”, “N()P3”, “H!”];
let re = /\wa\S!/;
- blahblah!!
- yea
- N()P3
- H!
52) Which line of code instantiates Adele and the album 21?
function PlayList(artist, album) {
this.artist = artist;
this.album = album;
};
- Adele.PlayList = (“Adele”, “21”);
- Adele = new PlayList(“Adele”, “21”);
- Adele new PlayList = (“Adele”, “21”);
- Adele = PlayList (“Adele”, “21”);
53) Which line of code creates a prototype method for PlayList called showCollection?
function PlayList(artist, album) {
this.artist = artist;
this.album = album;
};
- PlayList.prototype.showCollection = function() {
console.log(“My playlist so far: ” + this.artist + ” : ” + this.album);
};
- prototype.PlayList.showCollection = function() {
console.log(“My playlist so far: ” + this.artist + ” : ” + this.album);
};
- this.prototype.showCollection = function() {
console.log(“My playlist so far: ” + this.artist + ” : ” + this.album);
};
- PlayList.showCollection.prototype = function() {
console.log(“My playlist so far: ” + this.artist + ” : ” + this.album);
};
54) In strict mode, _____ variables must be declared.
- most
- some
- all
- no
55) Which function is in strict mode?
- function abc123() {
“restrict”;
}
- function abc123() {
“use strict”;
}
- function abc123() {
“strict”;
}
- function abc123() {
“strict mode”;
}
56) http://www.google.com and https://www.google.com are _____.
- different origins
- the same
- data sharers
- web storage objects
57) Which line of code deletes all data fromlocalStorage?
- localStorage.clear();
- localStorage.delete();
- localStorage.remove();
- localStorage.clearAll();
58) What does this line of code do?
localStorage.removeItem(“name”);
- Removes the “name” key and associated value from storage
- Removes the “name” key from storage
- Removes all values from storage
- Deletes a local variable named “name”