Q1. Which operator returns true if the two compared values are not equal?
Q2. How is a forEach statement different from a for statement?
Q3. Review the code below. Which statement calls the addTax function and passes 50 as an argument?
function addTax(total) {
return total * 1.05;
}
Q4. Which statement is the correct way to create a variable called rate and assign it the value 100?
Q5. Which statement creates a new object using the Person constructor? Which statement creates a new Person object called "student"?
Q6. When would the final statement in the code shown be logged to the console? When would 'results shown' be logged to the console?
let modal = document.querySelector('#result');
setTimeout(function () {
modal.classList.remove('hidden');
}, 10000);
console.log('Results shown');
Q7. Which snippet could you add to this code to print "food" to the console?
class Animal {
static belly = [];
eat() {
Animal.belly.push('food');
}
}
let a = new Animal();
a.eat();
console.log(/* Snippet Here */); //Prints food
Q8. You've written the code shown to log a set of consecutive values, but it instead results in the value 5, 5, 5, and 5 being logged to the console. Which revised version of the code would result in the value 1, 2, 3 and 4 being logged?
for (var i = 1; i <= 4; i++) {
setTimeout(function () {
console.log(i);
}, i * 10000);
}
for (var i = 1; i <= 4; i++) {
(function (i) {
setTimeout(function () {
console.log(j);
}, j * 1000);
})(j);
}
for (var i = 1; i <= 4; i++) {
setTimeout(function () {
console.log(i);
}, i * 1000);
}
for (var i = 1; i <= 4; i++) {
(function (j) {
setTimeout(function () {
console.log(j);
}, j * 1000);
})(i);
}
for (var j = 1; j <= 4; j++) {
setTimeout(function () {
console.log(j);
}, j * 1000);
}
Q10. Which statement creates a new function called discountPrice?
let discountPrice = function (price) {
return price * 0.85;
};
let discountPrice(price) {
return price * 0.85;
};
let function = discountPrice(price) {
return price * 0.85;
};
discountPrice = function (price) {
return price * 0.85;
};
Q11. What is the result in the console of running the code shown?
var Storm = function () {};
Storm.prototype.precip = 'rain';
var WinterStorm = function () {};
WinterStorm.prototype = new Storm();
WinterStorm.prototype.precip = 'snow';
var bob = new WinterStorm();
console.log(bob.precip);
Q12. You need to match a time value such as 12:00:32. Which of the following regular expressions would work for your code?
NOTE: The first three are all partially correct and will match digits, but the second option is the most correct because it will only match 2 digit time values (12:00:32). The first option would have worked if the repetitions range looked like [0-9]{2}, however because of the comma [0-9]{2,} it will select 2 or more digits (120:000:321). The third option will any range of time digits, single and multiple (meaning 1:2:3 will also match).
More resources:
Q13. What is the result in the console of running this code?
'use strict';
function logThis() {
this.desc = 'logger';
console.log(this);
}
new logThis();
Q14. How would you reference the text 'avenue' in the code shown?
let roadTypes = ['street', 'road', 'avenue', 'circle'];
Q15. What is the result of running this statement?
console.log(typeof 42);
Q17. You're adding error handling to the code shown. Which code would you include within the if statement to specify an error message?
function addNumbers(x, y) {
if (isNaN(x) || isNaN(y)) {
}
}
Q18. Which method converts JSON data to a JavaScript object?
Q20. What would be the result in the console of running this code?
for (var i = 0; i < 5; i++) {
console.log(i);
}
Q21. Which Object method returns an iterable that can be used to iterate over the properties of an object?
Q22. What will be logged to the console?
var a = ['dog', 'cat', 'hen'];
a[100] = 'fox';
console.log(a.length);
Q23. What is one difference between collections created with Map and collections created with Object?
Explanation: Map.prototype.size returns the number of elements in a Map, whereas Object does not have a built-in method to return its size.
Reference map methods javascript
Q24. What is the value of dessert.type after executing this code?
const dessert = { type: 'pie' };
dessert.type = 'pudding';
Q26. Which of the following operators can be used to do a short-circuit evaluation?
Q27. Which statement sets the Person constructor as the parent of the Student constructor in the prototype chain?
Q28. Why would you include a "use strict" statement in a JavaScript file?
Q29. Which Variable-defining keyword allows its variable to be accessed (as undefined) before the line that defines it?
Q32. Which variable is an implicit parameter for every function in JavaScript?
Q33. For the following class, how do you get the value of 42 from an instance of X?
class X {
get Y() {
return 42;
}
}
var x = new X();
Q34. What is the result of running this code?
sum(10, 20);
diff(10, 20);
function sum(x, y) {
return x + y;
}
let diff = function (x, y) {
return x - y;
};
Q35. Why is it usually better to work with Objects instead of Arrays to store a collection of records?
Reference efficiency of lookups Explanation: Records in an object can be retrieved using their key which can be any given value (e.g. an employee ID, a city name, etc), whereas to retrieve a record from an array we need to know its index.
Q36. Which statement is true about the "async" attribute for the HTML script tag?
Q37. How do you import the lodash library making it top-level Api available as the "_" variable?
Q39. What type of function can have its execution suspended and then resumed at a later point?
Q40. What will this code print?
var v = 1;
var f1 = function () {
console.log(v);
};
var f2 = function () {
var v = 2;
f1();
};
f2();
Q42. Your code is producing the error: TypeError: Cannot read property 'reduce' of undefined. What does that mean?
Explanation: You cannot invoke reduce on undefined object... It will throw (yourObject is not Defined...)
Q43. How many prototype objects are in the chain for the following array?
let arr = [];
Q45. What type of scope does the end variable have in the code shown?
var start = 1;
if (start === 1) {
let end = 2;
}
Q46. What will the value of y be in this code:
const x = 6 % 2;
const y = x ? 'One' : 'Two';
Q48. What's one difference between the async and defer attributes of the HTML script tag?
Q49. The following program has a problem. What is it?
var a;
var b = (a = 3) ? true : false;
Q50. Which statement references the DOM node created by the code shown?
<p class="pull">lorem ipsum</p>
Q51. What value does this code return?
let answer = true;
if (answer === false) {
return 0;
} else {
return 10;
}
Q52. What is the result in the console of running the code shown?
var start = 1;
function setEnd() {
var end = 10;
}
setEnd();
console.log(end);
Q53. What will this code log in the console?
function sayHello() {
console.log('hello');
}
console.log(sayHello.prototype);
Q55. What two values will this code print?
function printA() {
console.log(answer);
var answer = 1;
}
printA();
printA();
Q56. How does the forEach() method differ from a for statement?
Q57. Which choice is an incorrect way to define an arrow function that returns an empty object?
Q58. Why might you choose to make your code asynchronous?
EXPLANATION: "to ensure that tasks further down in your code are not initiated until earlier tasks have completed" you use the normal (synchronous) flow where each command is executed sequentially. Asynchronous code allows you to break this sequence: start a long running function (AJAX call to an external service) and continue running the rest of the code in parallel.
Q59. Which expression evaluates to true?
Q65. Which concept is defined as a template that can be used to generate different objects that share some shape and/or behavior?
Q67. If you attempt to call a value as a function but the value is not a function, what kind of error would you get?
Q68. Which method is called automatically when an object is initialized?
Q69. What is the result of running the statement shown?
let a = 5;
console.log(++a);
Q70. You've written the event listener shown below for a form button, but each time you click the button, the page reloads. Which statement would stop this from happening?
button.addEventListener(
'click',
function (e) {
button.className = 'clicked';
},
false,
);
Q71. Which statement represents the starting code converted to an IIFE?
Reference what is an Immediately Invoked Function Expression
Q75. Which event is fired on a text field within a form when a user tabs to it, or clicks or touches it?
Q76. What is the result in the console of running this code?
function logThis() {
console.log(this);
}
logThis();
Q77. Which class-based component is equivalent to this function component?
const Greeting = ({ name }) => <h1>Hello {name}!</h1>;
Q80. How would you use the TaxCalculator to determine the amount of tax on $50?
class TaxCalculator {
static calculate(total) {
return total * 0.05;
}
}
Q81. What is wrong with this code?
const foo = {
bar() {
console.log('Hello, world!');
},
name: 'Albert',
age: 26,
};
Q82. What will be logged to the console?
console.log('I');
setTimeout(() => {
console.log('love');
}, 0);
console.log('Javascript!');
I
Javascript!
love
love
I
Javascript!
I
love
Javascript!
Reference https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#reasonsfordelayslongerthan_specified especially see the 'late timeouts' section.
Q83. What will this code log to the console?
const foo = [1, 2, 3];
const [n] = foo;
console.log(n);
Q84. How do you remove the property name from this object?
const foo = {
name: 'Albert',
};
Q85. What is the difference between the map() and the forEach() methods on the Array prototype?
Q86. Which concept does this code illustrate?
function makeAdder(x) {
return function (y) {
return x + y;
};
}
var addFive = makeAdder(5);
console.log(addFive(3));
Q88. If your app receives data from a third-party API, which HTTP response header must the server specify to allow exceptions to the same-origin policy?
Q89. What is the output of this code?
let rainForests = ['Amazon', 'Borneo', 'Cerrado', 'Congo'];
rainForests.splice(0, 2);
console.log(rainForests);
Q90. Which missing line would allow you to create five variables(one,two,three,four,five) that correspond to their numerical values (1,2,3,4,5)?
const numbers = [1, 2, 3, 4, 5];
//MISSING LINE
Q91. What will this code print?
const obj = {
a: 1,
b: 2,
c: 3,
};
const obj2 = {
...obj,
a: 0,
};
console.log(obj2.a, obj2.b);
Q92. Which line could you add to this code to print "jaguar" to the console?
let animals = ['jaguar', 'eagle'];
//Missing Line
console.log(animals.pop()); //Prints jaguar
Reference Javascript Array pop()
shift() - removes the FIRST element of an array and returns the removed item.
pop() - removes the LAST element of an array and returns the removed item.
reverse() - reverses the order of the elements in an array.
filter() - get every element in the array that meets the condition.
Q93. What line is missing from this code?
//Missing Line
for (var i = 0; i < vowels.length; i++) {
console.log(vowels[i]);
//Each letter printed on a separate line as follows;
//a
//e
//i
//o
//u
}
Q94. What will be logged to the console?
const x = 6 % 2;
const y = x ? 'One' : 'Two';
console.log(y);
Note: this question is same with Q46.
Reference ternary operator js
Q95. How would you access the word It from this multidimensional array?
let matrix = [["You","Can"],["Do","It"],["!","!","!"]];
Q96. What does this code do?
const animals = ['Rabbit', 'Dog', 'Cat'];
animals.unshift('Lizard');
Q98. Which statement can take a single expression as input and then look through a number of choices until one that matches that value is found?
Q99. Which statement prints "roar" to the console?
var sound = 'grunt';
var bear = { sound: 'roar' };
function roar() {
console.log(this.sound);
}
Q100. Which choice is a valid example of an arrow function, assuming c is defined in the outer scope?
Q101. Which statement correctly imports this code from some-file.js?
//some-file.js
export const printMe = (str) => console.log(str);
Q102. What will be the output of this code?
const arr1 = [2, 4, 6];
const arr2 = [3, 5, 7];
console.log([...arr1, ...arr2]);
Q103. Which method call is chained to handle a successful response returned by fetch()?
Q105. Which JavaScript loop ensures that at least a singular iteration will happen?
Q107. What is the output that is printed when the div containing the text "Click Here" is clicked?
//HTML Markup
<div id="A">
<div id="B">
<div id="C">Click Here</div>
</div>
</div>
//JavaScript
document.querySelectorAll('div').forEach((e) => {
e.onclick = (e) => console.log(e.currentTarget.id);
});
Q108. What will this code log to the console?
const myNumbers = [1, 2, 3, 4, 5, 6, 7];
const myFunction = (arr) => {
return arr.map((x) => x + 3).filter((x) => x < 7);
};
console.log(myFunction(myNumbers));
Q109. What does this code print to the console?
let rainForestAcres = 10;
let animals = 0;
while (rainForestAcres < 13 || animals <= 2) {
rainForestAcres++;
animals += 2;
}
console.log(animals);
Q110. Which snippet could you add to this code to print "YOU GOT THIS" to the console?
let cipherText = [...'YZOGUT QGMORTZ MTRHTILS'];
let plainText = '';
/* Missing Snippet */
console.log(plainText); //Prints YOU GOT THIS
for (let key of cipherText.keys()) {
plainText += key % 2 === 0 ? key : ' ';
}
for (let [index, value] of cipherText.entries()) {
plainText += index % 2 !== 0 ? value : '';
}
for (let [index, value] of cipherText.entries()) {
plainText += index % 2 === 0 ? value : '';
}
for (let value of cipherText) {
plainText += value;
}
Q111. Which Pokemon will be logged to the console?
var pokedex = ['Snorlax', 'Jigglypuff', 'Charmander', 'Squirtle'];
pokedex.pop();
console.log(pokedex.pop());
Explanation: The pop() method removes the last element from an array and returns that element. This method changes the length of the array.
Q112. Which statement can be used to select the element from the DOM containing the text "The LinkedIn Learning library has great JavaScript courses" from this markup?
<h1 class="content">LinkedIn Learning</h1>
<div class="content">
<span class="content">The LinkedIn Learning library has great JavaScript courses!</span>
</div>
Q114. What line of code causes this code segment to throw an error?
const lion = 1;
let tiger = 2;
var bear;
++lion;
bear += lion + tiger;
tiger++;
Q115. What will be the value of result after running this code?
const person = { name: 'Dave', age: 40, hairColor: 'blue' };
const result = Object.keys(person).map((x) => x.toUpperCase());
Q116. Which snippet could you insert to this code to print "swim" to the console?
let animals = ["eagle", "osprey", "salmon"];
let key = animal => animal === "salmon";
if(/* Insert Snippet Here */){
console.log("swim");
}
Q117. What is the output of this code?
class RainForest {
static minimumRainFall = 60;
}
let congo = new RainForest();
RainForest.minimumRainFall = 80;
console.log(congo.minimumRainFall);
Q118. How can you attempt to access the property a.b on obj without throwing an error if a is undefined?
let obj = {};
Q119. What happens when you run this code?
if (true) {
var x = 5;
const y = 6;
let z = 7;
}
console.log(x + y + z);
Q120. What does this code print to the console?
const x = [1, 2];
const y = [5, 7];
const z = [...x, ...y];
console.log(z);
Q121. Given this code, which statement will be evaluated as false?
const a = { x: 1 };
const b = { x: 1 };
Q123. What is the output of this code?
let scores = [];
scores.push(1, 2);
scores.pop();
scores.push(3, 4);
scores.pop();
score = scores.reduce((a, b) => a + b);
console.log(score);
Q124. What does this code print to the console?
let bear = {
sound: 'roar',
roar() {
console.log(this.sound);
},
};
bear.sound = 'grunt';
let bearSound = bear.roar;
bearSound();
Q125. What is the output of this code?
var cat = { name: 'Athena' };
function swap(feline) {
feline.name = 'Wild';
feline = { name: 'Tabby' };
}
swap(cat);
console.log(cat.name);
Q126. What will this code output to the log?
var thing;
let func = (str = 'no arg') => {
console.log(str);
};
func(thing);
func(null);
Q127. What will this code print to the console?
const myFunc = () => {
const a = 2;
return () => console.log('a is ' + a);
};
const a = 1;
const test = myFunc();
test();
Q128. What will this code print to the console?
const myFunc = (num1, num2 = 2, num3 = 2) => {
return num1 + num2 + num3;
};
let values = [1, 5];
const test = myFunc(2, ...values);
console.log(test);
Q129. Which code would you use to access the Irish flag?
var flagsJSON =
'{ "countries" : [' +
'{ "country":"Ireland" , "flag":"🇮🇪" },' +
'{ "country":"Serbia" , "flag":"🇷🇸" },' +
'{ "country":"Peru" , "flag":"🇵🇪" } ]}';
var flagDatabase = JSON.parse(flagsJSON);
Q130. Which snippet allows the acresOfRainForest variable to increase?
let conservation = true;
let deforestation = false;
let acresOfRainForest = 100;
if (/* Snipped goes here */){
++acresOfRainForest;
}
Q131. Which of these evaluate to true?
Q132. How would you add a data item named animal with a value of sloth to local storage for the current domain?
Q133. What value is printed to the console after this code execute?
let cat = Object.create({ type: 'lion' });
cat.size = 'large';
let copyCat = { ...cat };
cat.type = 'tiger';
console.log(copyCat.type, copyCat.size);
Q134. What does this code print to the console?
let animals = [{ type: 'lion' }, 'tiger'];
let clones = animals.slice();
clones[0].type = 'bear';
clones[1] = 'sheep';
console.log(animals[0].type, clones[0].type);
console.log(animals[1], clones[1]);
Q135. What will be the output of the following code?
a=5;
b=4;
alert(a++(+(+(+b))));
Q136. Which snippet could you add to this code to print "{"type": "tiger"}" to the console?
let cat = { type: "tiger", size: "large" };
let json = /* Snippet here */;
console.log(json); // print {"type":"tiger"}
Q140. What will be the output of the following code snippet?
const obj1 = { first: 20, second: 30, first: 50 };
console.log(obj1);
Q142. What does … operator do in JS?
Q144. What will be the output of the following code snippet?
print(typeof NaN);
Q145. What will be the output of the following code snippet?
<script type="text/javascript">a = 5 + "9"; document.write(a);</script>
Q146. Which of the following methods can be used to display data in some form using Javascript?
Q147. What value is assigned to total after this code executes?
function sum(num1, num2 = 2, num3 = 3) {
return num1 + num2 + num3;
}
let values = [1, 5];
let total = sum(4, ...values);
Q148. Which statement is applicable to the defer attribute of the HTML tag?
Q149. Which method of a class is called to initialize an object of that class?
Q151. How would you check if the word "pot" is in the word "potato"?
Q152. Which collection object allows a unique value to be inserted only once?
Q153. How would you change the color of this header to pink?
<h2 id="cleverest">girls</h2>
Q154. Which line is missing from this code if you expect the code to evaluate to true?
var compare = function (test1, test2) {
// Missing line
};
compare(1078, '1078'); // yields true
Q155. What is the output of this code?
if (true) {
var first = 'You';
}
function fScope() {
var second = 'got this!';
}
fScope();
console.log(first);
console.log(second);
Q156. What is the output for the code given below?
console.log('hello' + 'world' + '!');
Q157. What is the output of this code?
console.log(10 + 10);
Q160. Your code is producing the error: TypeError: Cannot read property 'reduce' of undefined. What does that mean?
Q161. Which of the following methods can be used to display data in some form using Javascript?
Q162. Which document method is not used to get a reference to a DOM node?
Q163. Which of these is a valid variable name?
Q164. What function is used in JavaScript to schedule a function to run after a specified number of milliseconds?
Q166. Which statement best describes the var keyword's scope in JavaScript?
Q167. What will be logged to the console?
const foo = () => console.log('First');
const bar = () => setTimeout(() => console.log('Second'), 0);
foo();
bar();
console.log('Third');
Q168. What will be the output of running this code?
function scream(words) {
return words.toUpperCase() + '!!!';
}
scream('yay');