linkedin-skill-assessments-quizzes

JavaScript

Q1. Which operator returns true if the two compared values are not equal?

Reference Javascript Comparison Operators

Q2. How is a forEach statement different from a for statement?

Reference Differences between forEach and for loop

Q3. Review the code below. Which statement calls the addTax function and passes 50 as an argument? How would you use this function to find out how much tax should be paid on $50?

function addTax(total) {
  return total * 1.05;
}

Reference functions in javascript

Q4. Which statement is the correct way to create a variable called rate and assign it the value 100?

Reference Javascript Assignment operators

Q5. Which statement creates a new object using the Person constructor? Which statement creates a new Person object called “student”?

Reference

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');

Reference Javascript is synchronous and single threaded

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

Reference Javascript Class static Keyword

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);
}
while (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);
}
  1. Reference setTimeout
  2. Reference immediately invoked anonymous functions

Q9. How does a function create a closure?

Reference

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;
};

Reference defining javascript functions

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);

Reference prototype chain

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:

  1. Repeating characters
  2. Kleene operators

Q13. What is the result in the console of running this code?

'use strict';
function logThis() {
  this.desc = 'logger';
  console.log(this);
}
new logThis();

Reference javascript classes

Q14. How would you reference the text ‘avenue’ in the code shown?

let roadTypes = ['street', 'road', 'avenue', 'circle'];

Reference accessing javascript arrays

Q15. What is the result of running this statement?

console.log(typeof 42);

Reference javascript data types

Q16. Which property references the DOM object that dispatched an event?

Reference DOM events

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)) {
  }
}

Reference javascript throw

Q18. Which method converts JSON data to a JavaScript object?

Reference convert json to javascript object

Q19. When would you use a conditional statement?

Reference javascript conditionals

Q20. What would be the result in the console of running this code?

for (var i = 0; i < 5; i++) {
  console.log(i);
}

Reference javascript for loops

Q21. Which Object method returns an iterable that can be used to iterate over the properties of an object?

Reference javascript object static methods

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';

Reference working with js objects

Q25. 0 && hi

Reference boolean logic

Q26. Which of the following operators can be used to do a short-circuit evaluation?

Reference short circuit javascript

Q27. Which statement sets the Person constructor as the parent of the Student constructor in the prototype chain?

Reference prototype object js

Q28. Why would you include a “use strict” statement in a JavaScript file?

Reference what is use strict in js

Q29. Which Variable-defining keyword allows its variable to be accessed (as undefined) before the line that defines it?

Reference var vs let vs const in js

Q30. Which of the following values is not a Boolean false?

Reference boolean of a string

Q31. Which of the following is not a keyword in JavaScript?

Reference js reserved words

Q32. Which variable is an implicit parameter for every function in JavaScript?

Reference implicit js parameters for functions

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();

Reference getters

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;
};

Reference accessing before initialization

Q35. Why is it usually better to work with Objects instead of Arrays to store a collection of records?

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. Reference efficiency of lookups

Q36. Which statement is true about the “async” attribute for the HTML script tag?

Reference async attribute for html

Q37. How do you import the lodash library making it top-level Api available as the “_” variable?

Reference how to import library in js

Q38. What does the following expression evaluate to?

[] == [];

Reference arrays in js are objects

Q39. What type of function can have its execution suspended and then resumed at a later point?

Reference what are generators in nodejs

Q40. What will this code print?

var v = 1;
var f1 = function () {
  console.log(v);
};

var f2 = function () {
  var v = 2;
  f1();
};

f2();

Reference closures in js \/ nested functions

Q41. Which statement is true about Functional Programming?

Reference functional programming

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 = [];

Reference array prototype

Q44. Which choice is not a unary operator?

Reference js unary operators

Q45. What type of scope does the end variable have in the code shown?

var start = 1;
if (start === 1) {
  let end = 2;
}

Reference block vs function scope

Q46. What will the value of y be in this code:

const x = 6 % 2;
const y = x ? 'One' : 'Two';

Reference ternary operator js

Q47. Which keyword is used to create an error?

Reference throwing errors in js

Q48. What’s one difference between the async and defer attributes of the HTML script tag?

Reference async vs defer

Q49. The following program has a problem. What is it?

var a;
var b = (a = 3) ? true : false;

Reference ternary operator js

Q50. Which statement references the DOM node created by the code shown?

<p class="pull">lorem ipsum</p>

Reference query selector

Q51. What value does this code return?

let answer = true;
if (answer === false) {
  return 0;
} else {
  return 10;
}

Reference javascript conditionals

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);

Reference

Q53. What will this code log in the console?

function sayHello() {
  console.log('hello');
}

console.log(sayHello.prototype);

Reference prototypes

Q54. Which collection object allows unique value to be inserted only once?

Reference javascript sets

Q55. What two values will this code print?

function printA() {
  console.log(answer);
  var answer = 1;
}
printA();
printA();

Reference

Q56. How does the forEach() method differ from a for statement?

Reference Differences between forEach and for loop

Q57. Which choice is an incorrect way to define an arrow function that returns an empty object?

Reference arrow functions

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?

Reference booleans

Q60. Which of these is a valid variable name?

Reference coding conventions

Q61. Which method cancels event default behavior?

Reference javascript events

Q62. Which method do you use to attach one DOM node to another?

Reference Node interface

Q63. Which statement is used to skip iteration of the loop?

Reference break vs continue

Q64. Which choice is valid example for an arrow function?

Reference arrow functions

Q65. Which concept is defined as a template that can be used to generate different objects that share some shape and/or behavior?

Reference javascript classes

Q66. How do you add a comment to JavaScript code?

Reference comments in javascript

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?

Reference javascript errors

Q68. Which method is called automatically when an object is initialized?

Reference javascript constructors

Q69. What is the result of running the statement shown?

let a = 5;
console.log(++a);

Reference ++x vs x++

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,
);

Reference events in javascript

Q71. Which statement represents the starting code converted to an IIFE?

Reference what is an Immediately Invoked Function Expression

Q72. Which statement selects all img elements in the DOM tree?

Reference query selector

Q73. Why would you choose an asynchronous structure for your code?

Reference async function

Q74. What is the HTTP verb to request the contents of an existing resource?

Reference http methods

Q75. Which event is fired on a text field within a form when a user tabs to it, or clicks or touches it?

Reference javascript events

Q76. What is the result in the console of running this code?

function logThis() {
  console.log(this);
}
logThis();

Reference what is the javascript window

Q77. Which class-based component is equivalent to this function component?

const Greeting = ({ name }) => <h1>Hello {name}!</h1>;

Q78. Which class-based lifecycle method would be called at the same time as this effect Hook?

useEffect(() => {
  // do things
}, []);

Reference react lifecycle methods

Q79. What is the output of this code?

var obj;
console.log(obj);

Reference working with objects

Q80. How would you use the TaxCalculator to determine the amount of tax on $50?

class TaxCalculator {
  static calculate(total) {
    return total * 0.05;
  }
}

Reference functions in javascript

Q81. What is wrong with this code?

const foo = {
  bar() {
    console.log('Hello, world!');
  },
  name: 'Albert',
  age: 26,
};
  1. Reference functions in javascript
  2. Reference working with objects

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#reasons_for_delays_longer_than_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);

Reference array deconstruction

Q84. How do you remove the property name from this object?

const foo = {
  name: 'Albert',
};

Reference working with objects

Q85. What is the difference between the map() and the forEach() methods on the Array prototype?

  1. Reference map
  2. Reference Differences between forEach and for loop

Q86. Which concept does this code illustrate?

function makeAdder(x) {
  return function (y) {
    return x + y;
  };
}

var addFive = makeAdder(5);
console.log(addFive(3));

Reference currying

Q87. Which tag pair is used in HTML to embed JavaScript?

Reference add js to html file

Q88. What would be the result in the console of running this code?

for (var i = 0; i < 5; i++) {
  console.log(i);
}

Reference Differences between forEach and for loop

Q89. What is the value of dessert.type after executing this code?

const dessert = { type: 'pie' };
dessert.type = 'pudding';

const seconds = dessert;
seconds.type = 'fruit';

Explanation: Assigning a variable (such as seconds) to an object (such as dessert) does not create a new object. The seconds variable merely becomes a reference for the dessert object. Any changes made to seconds will also reflect in dessert.

Q90. 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?

Reference Cross-Origin Resource Sharing

Q91. What will be logged to the console??

'use strict';
function logThis() {
  this.desc = 'logger';
  console.log(this);
}
new logThis();

Reference strict in javascript classes

Q92. Which statement is applicable to the defer attribute of the HTML <script> tag?

Explanation: If the defer attribute is set, it specifies that the script is downloaded in parallel to parsing the page, and executed after the page has finished parsing. HTML <script> defer Attribute

Q93. What will this code print?

let rainForests = ['Amazon', 'Borneo', 'Cerrado', 'Congo'];
rainForests.splice(0, 2);
console.log(rainForests);

Reference array methods

Q94. 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

Reference array destructuring

Q95. What will this code print?

const obj = {
  a: 1,
  b: 2,
  c: 3,
};

const obj2 = {
  ...obj,
  a: 0,
};

console.log(obj2.a, obj2.b);

Reference spread syntax es6

Q96. 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 Reverse

Q97. 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
}

Reference working with arrays

Q98. What will be logged to the console?

const x = 6 % 2;
const y = x ? 'One' : 'Two';
console.log(y);

Reference ternary operator js

Q99. How would you access the word It from this multidimensional array?

let matrix = [["You","Can"],["Do","It"],["!","!","!"]];

Q100. What does this code do?

const animals = ['Rabbit', 'Dog', 'Cat'];
animals.unshift('Lizard');

Reference working with arrays

Q101. What is the output of this code?

let x = 6 + 3 + '3';
console.log(x);

Reference type coercion

Q102. 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?

Reference switch

Q103. Which statement prints “roar” to the console?

var sound = 'grunt';
var bear = { sound: 'roar' };
function roar() {
  console.log(this.sound);
}
  1. Reference Apply
  2. Reference this
  3. Reference bind

Q104. Which choice is a valid example of an arrow function, assuming c is defined in the outer scope?

Reference arrow functions

Q105. 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);

Reference working with objects

Q106. Which statement correctly imports this code from some-file.js?

//some-file.js
export const printMe = (str) => console.log(str);

Reference importing libraries in javascript

Q107. What will be the output of this code?

const arr1 = [2, 4, 6];
const arr2 = [3, 5, 7];

console.log([...arr1, ...arr2]);

Reference spread syntax

Q108. Which method call is chained to handle a successful response returned by fetch()?

Reference fetch

Q109. Which choice is not an array method?

Reference working with arrays

Q110. Which JavaScript loop ensures that at least a singular iteration will happen?

Reference loops in js

Q111. What will be logged to the console?

console.log(typeof 'blueberry');

Reference what is typeof

Q112. 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);
});
  1. Reference query selector
  2. Reference events

Q113. 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));

Reference functions in javascript

Q114. 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);

Reference MDN JavaScript Looping code

Q115. 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;
}
  1. Reference MDN JavaScript Destructuring
  2. Reference MDN JavaScript Array entries
  3. Reference MDN JavaScript Remainder/Modulo

Q116. What will this code log to the console?

const foo = [1, 2, 3];
const [n] = foo;
console.log(n);

Q117. 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.

Reference Array.pop

Q118. Which snippet allows the acresOfRainForest variable to increase?

let conservation = true;
let deforestation = false;
let acresOfRainForest = 100;

if(/* Snippet goes here */){
    ++acresOfRainForest;
}

Reference if…else statements

Q119. 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>

Q120. Which value is not falsey?

Reference Falsy

Q121. 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++;
  1. Reference const in js
  2. Reference TypeError: invalid assignment to const “x”

Q122. 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());
  1. Reference Object.keys()
  2. Reference Array.prototype.map()
  3. Reference String.prototype.toUpperCase()

Q123. 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");
}

Reference Array.prototype.some

Q124. What is the output of this code?

class RainForest {
  static minimumRainFall = 60;
}

let congo = new RainForest();
RainForest.minimumRainFall = 80;
console.log(congo.minimumRainFall);

Reference Classes static

Q125. How can you attempt to access the property a.b on obj without throwing an error if a is undefined?

let obj = {};

Reference Optional chaining (?.)

Q126. What happens when you run this code?

if (true) {
  var x = 5;
  const y = 6;
  let z = 7;
}
console.log(x + y + z);

Reference let statement

Q127. What does this code print to the console?

const x = [1, 2];
const y = [5, 7];
const z = [...x, ...y];
console.log(z);

Reference spread syntax (…)

Q128. Given this code, which statement will evaluate to false?

const a = { x: 1 };
const b = { x: 1 };

Reference

Q129. What will this code log to the console?

console.log(typeof 41.1);

Reference

Q130. 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);
  1. Reference
  2. Reference
  3. Reference

Q131. 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();

Reference

Q132. 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);

Q133. What will this code output to the log?

var thing;
let func = (str = 'no arg') => {
  console.log(str);
};
func(thing);
func(null);

Q134. 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();

Q135. 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);