JavaScript LinkedIn Skill Assessment Answer 2023

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

  1. <>
  2. ~
  3. ==!
  4. !==✔️

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

  1. Only a for statement uses a callback function.
  2. A for statement is generic, but a forEach statement can be used only with an array.✔️
  3. Only a forEach statement lets you specify your own iterator.
  4. A forEach statement is generic, but a for statement can be used only with an array.

Q3. Review the code below. Which statement calls the addTax function and passes 50 as an argument?

or

Q3. How would you use this function to find out how much tax should be paid on $50?

function addTax(total) {
  return total * 1.05;
}
  1. addTax = 50;
  2. return addTax 50;
  3. addTax(50);✔️
  4. addTax 50;

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

  1. let rate = 100;✔️
  2. let 100 = rate;
  3. 100 = let rate;
  4. rate = 100;

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

  1. var student = new Person();✔️
  2. var student = construct Person;
  3. var student = Person();
  4. var student = construct Person();

Q6. When would the final statement in the code shown be logged to the console?

let modal = document.querySelector('#result');
setTimeout(function(){
    modal.classList.remove('hidden);
}, 10000);
console.log('Results shown');
  1. after 10 second
  2. after results are received from the HTTP request
  3. after 10000 seconds
  4. immediately✔️

Q7. When would ‘results shown’ be logged to the console?

let modal = document.querySelector('#results');
setTimeout(function () {
  modal.classList.remove('hidden');
}, 10000);
  1. immediately✔️
  2. after results are received from the HTTP request
  3. after 10 second
  4. after 10,000 seconds

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);
}
  1. A
for (var i = 1; i <= 4; i++) {
  (function (i) {
    setTimeout(function () {
      console.log(j);
    }, j * 1000);
  })(j);
}
  1. B
while (var i=1; i<=4; i++) {
  setTimeout(function() {
    console.log(i);
    }, i*1000);
}
  1. C✔️
for (var i = 1; i <= 4; i++) {
  (function (j) {
    setTimeout(function () {
      console.log(j);
    }, j * 1000);
  })(i);
}
  1. D
for (var j = 1; j <= 4; j++) {
  setTimeout(function () {
    console.log(j);
  }, j * 1000);
}

Q9. How does a function create a closure?

  1. It reloads the document whenever the value changes.
  2. It returns a reference to a variable in its parent scope.✔️
  3. It completes execution without returning.
  4. It copies a local variable to the global scope.

Q10. Which statement creates a new function called discountPrice?

  1. A✔️
let discountPrice = function (price) {
  return price * 0.85;
};
  1. B
let discountPrice(price) {
  return price * 0.85;
};
  1. C
let function = discountPrice(price) {
  return price * 0.85;
};
  1. D
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);
  1. Storm()
  2. undefined
  3. ‘rain’
  4. ‘snow’✔️

Q12. You need to match a time value such as 12:00:32. Which of the following regular expressions would work for your code?

  1. /[0-9]{2,}:[0-9]{2,}:[0-9]{2,}/
  2. /\d\d:\d\d:\d\d/✔️
  3. /[0-9]+:[0-9]+:[0-9]+/
  4. / : : /

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

'use strict';
function logThis() {
  this.desc = 'logger';
  console.log(this);
}
new logThis();
  1. undefined
  2. window
  3. {desc: “logger”}✔️
  4. function

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

let roadTypes = [‘street’, ‘road’, ‘avenue’, ‘circle’];

  1. roadTypes.2
  2. roadTypes[3]
  3. roadTypes.3
  4. roadTypes[2]✔️

Q15. What is the result of running this statement?

console.log(typeof 42);

  1. ‘float’
  2. ‘value’
  3. ‘number’✔️
  4. ‘integer’

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

  1. self
  2. object
  3. target✔️
  4. source

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)) {
  }
}
  1. exception(‘One or both parameters are not numbers’)
  2. catch(‘One or both parameters are not numbers’)
  3. error(‘One or both parameters are not numbers’)
  4. throw(‘One or both parameters are not numbers’)✔️

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

  1. JSON.fromString();
  2. JSON.parse()✔️
  3. JSON.toObject()
  4. JSON.stringify()

Q19. When would you use a conditional statement?

  1. When you want to reuse a set of statements multiple times.
  2. When you want your code to choose between multiple options.✔️
  3. When you want to group data together.
  4. When you want to loop through a group of statement.

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

for (var i = 0; i < 5; i++) {
  console.log(i);
}
  1. 12345
  2. 1234
  3. 01234✔️
  4. 012345

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

  1. Object.get()
  2. Object.loop()
  3. Object.each()
  4. Object.keys()✔️

Q22. What will be logged to the console?

var a = ['dog', 'cat', 'hen'];
a[100] = 'fox';
console.log(a.length);
  1. 101✔️
  2. 3
  3. 4
  4. 100

Q23. What is one difference between collections created with Map and collections created with Object?

  1. You can iterate over values in a Map in their insertion order.
  2. You can count the records in a Map with a single method call.✔️
  3. Keys in Maps can be strings.
  4. You can access values in a Map without iterating over the whole collection.

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

const dessert = { type: 'pie' };
dessert.type = 'pudding';
  1. pie
  2. The code will throw an error.
  3. pudding✔️
  4. undefined

Q25. 0 && hi

  1. ReferenceError
  2. True
  3. 0✔️
  4. false

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

  1. ++
  2. ==
  3. ||✔️

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

  1. Student.parent = Person;
  2. Student.prototype = new Person();✔️
  3. Student.prototype = Person;
  4. Student.prototype = Person();

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

  1. to tell parsers to interpret your JavaScript syntax loosely
  2. to tell parsers to enforce all JavaScript syntax rules when processing your code✔️
  3. to instruct the browser to automatically fix any errors it finds in the code
  4. to enable ES6 features in your code

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

  1. all of them
  2. const
  3. var✔️
  4. let

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

  1. Boolean(0)
  2. Boolean(“”)
  3. Boolean(NaN)
  4. Boolean(“false”)✔️

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

  1. this
  2. catch
  3. function
  4. array✔️

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

  1. Arguments✔️
  2. args
  3. argsArray
  4. argumentsList

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();
  1. x.get(‘Y’)
  2. x.Y✔️
  3. x.Y()
  4. x.get().Y

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;
};
  1. 30, ReferenceError, 30, -10
  2. 30, ReferenceError✔️
  3. 30, -10
  4. ReferenceError, -10

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

  1. Objects are more efficient in terms of storage.
  2. Adding a record to an object is significantly faster than pushing a record into an array.
  3. Most operations involve looking up a record, and objects can do that better than arrays.✔️
  4. Working with objects makes the code more readable.

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

  1. It can be used for both internal and external JavaScript code.
  2. It can be used only for internal JavaScript code.
  3. It can be used only for internal or external JavaScript code that exports a promise.
  4. It can be used only for external JavaScript code.✔️

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

  1. import _ from ‘lodash’;✔️
  2. import ‘lodash’ as _;
  3. import ‘_’ from ‘lodash;
  4. import lodash as _ from ‘lodash’;

Q38. What does the following expression evaluate to?

[] == [];

  1. True
  2. undefined
  3. []
  4. False✔️

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

  1. Generator function✔️
  2. Arrow function
  3. Async/ Await function
  4. Promise function

Q40. What will this code print?

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

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

f2();
  1. 2
  2. 1✔️
  3. Nothing – this code will throw an error.
  4. undefined

Q41. Which statement is true about Functional Programming?

  1. Every object in the program has to be a function.
  2. Code is grouped with the state it modifies.
  3. Date fields and methods are kept in units.
  4. Side effects are not allowed.✔️

Q42. Your code is producing the error: TypeError: Cannot read property ‘reduce’ of undefined. What does that mean?

  1. You are calling a method named reduce on an object that’s declared but has no value.✔️
  2. You are calling a method named reduce on an object that does not exist.
  3. You are calling a method named reduce on an empty array.
  4. You are calling a method named reduce on an object that’s has a null value.

Q43. How many prototype objects are in the chain for the following array?

let arr = [];

  1. 3
  2. 2✔️
  3. 0
  4. 1

Q44. Which choice is not a unary operator?

  1. typeof
  2. delete
  3. instanceof✔️
  4. void

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

var start = 1;
if (start === 1) {
  let end = 2;
}
  1. conditional
  2. block✔️
  3. global
  4. function

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

const x = 6 % 2;
const y = x ? 'One' : 'Two';
  1. One
  2. undefined
  3. TRUE
  4. Two✔️

Q47. Which keyword is used to create an error?

  1. throw✔️
  2. exception
  3. catch
  4. error

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

  1. The defer attribute can work synchronously.
  2. The defer attribute works only with generators.
  3. The defer attribute works only with promises.
  4. The defer attribute will asynchronously load the scripts in order.✔️

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

var a;
var b = (a = 3) ? true : false;
  1. The condition in the ternary is using the assignment operator.✔️
  2. You can’t define a variable without initializing it.
  3. You can’t use a ternary in the right-hand side of an assignment operator.
  4. The code is using the deprecated var keyword.

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

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

  1. Document.querySelector(‘class.pull’)
  2. document.querySelector(‘.pull’);✔️
  3. Document.querySelector(‘pull’)
  4. Document.querySelector(‘#pull’)

Q51. What value does this code return?

let answer = true;
if (answer === false) {
  return 0;
} else {
  return 10;
}
  1. 10✔️
  2. true
  3. false
  4. 0

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);
  1. 10
  2. 0
  3. ReferenceError✔️
  4. undefined

Q53. What will this code log in the console?

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

console.log(sayHello.prototype);
  1. undefined
  2. “hello”
  3. an object with a constructor property✔️
  4. an error message

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

  1. Object
  2. Set✔️
  3. Array
  4. Map

Q55. What two values will this code print?

function printA() {
  console.log(answer);
  var answer = 1;
}
printA();
printA();
  1. 1 then 1
  2. 1 then undefined
  3. undefined then undefined✔️
  4. undefined then 1

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

  1. forEach allows you to specify your own iterator, whereas for does not.
  2. forEach can be used only with strings, whereas for can be used with additional data types.
  3. forEach can be used only with an array, whereas for can be used with additional data types.✔️
  4. for loops can be nested; whereas forEach loops cannot.

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

  1. => ({})
  2. => {}✔️
  3. => { return {};}
  4. => (({}))

Q58. Why might you choose to make your code asynchronous?

  1. to start tasks that might take some time without blocking subsequent tasks from executing immediately✔️
  2. to ensure that tasks further down in your code are not initiated until earlier tasks have completed
  3. to make your code faster
  4. to ensure that the call stack maintains a LIFO (Last in, First Out) structure

Q59. Which expression evaluates to true?

  1. [3] == [3]
  2. 3 == ‘3’✔️
  3. 3 != ‘3’
  4. 3 === ‘3’

Q60. Which of these is a valid variable name?

  1. 5thItem
  2. firstName✔️
  3. grand total
  4. function

Q61. Which method cancels event default behavior?

  1. cancel()
  2. stop()
  3. preventDefault()✔️
  4. prevent()

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

  1. attachNode()
  2. getNode()
  3. querySelector()
  4. appendChild()✔️

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

  1. break
  2. pass
  3. skip
  4. continue✔️

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

  1. (a,b) => c✔️
  2. a, b => {return c;}
  3. a, b => c
  4. { a, b } => c

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

  1. class✔️
  2. generator function
  3. map
  4. proxy

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

  1. ! This is a comment
  2. #This is a comment
  3. \ This is a comment
  4. // This is a comment✔️

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?

  1. TypeError✔️
  2. SystemError
  3. SyntaxError
  4. LogicError

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

  1. create()
  2. new()
  3. constructor()✔️
  4. init()

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

let a = 5;
console.log(++a);
  1. 4
  2. 10
  3. 6✔️
  4. 5

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,
);
  1. e.blockReload();
  2. button.preventDefault();
  3. button.blockReload();
  4. e.preventDefault();✔️

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

  1. function() { console.log(‘lorem ipsum’); }()();
  2. function() { console.log(‘lorem ipsum’); }();
  3. (function() { console.log(‘lorem ipsum’); })();✔️

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

  1. Document.querySelector(‘img’)
  2. Document.querySelectorAll(‘<img>’)
  3. Document.querySelectorAll(‘img’)✔️
  4. Document.querySelector(‘<img>’)

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

  1. To use ES6 syntax
  2. To start tasks that might take some time without blocking subsequent tasks from executing immediately✔️
  3. To ensure that parsers enforce all JavaScript syntax rules when processing your code
  4. To ensure that tasks further down in your code aren’t initiated until earlier tasks have completed

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

  1. DELETE
  2. GET✔️
  3. PATCH
  4. POST

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

  1. focus✔️
  2. blur
  3. hover
  4. enter

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

function logThis() {
  console.log(this);
}
logThis();
  1. function
  2. undefined
  3. Function.prototype
  4. window✔️

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

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

  1. class Greeting extends React.Component { render() { return <h1>Hello {this.props.name}!</h1>; } }✔️
  2. class Greeting extends React.Component { constructor() { return <h1>Hello {this.props.name}!</h1>; } }
  3. class Greeting extends React.Component { <h>Hello {this.props.name}!</h>; } }
  4. class Greeting extends React.Component { render({ name }) { return <h1>Hello {name}!</h1>; } }

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

useEffect(() => {
  // do things
}, []);
  1. componentWillUnmount
  2. componentDidUpdate
  3. render
  4. componentDidMount✔️

Q79. What is the output of this code?

var obj;
console.log(obj);
  1. ReferenceError: obj is not defined
  2. {}
  3. undefined✔️
  4. null

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

class TaxCalculator {
  static calculate(total) {
    return total * 0.05;
  }
}
  1. calculate(50);
  2. new TaxCalculator().calculate($50);
  3. TaxCalculator.calculate(50);✔️
  4. new TaxCalculator().calculate(50);

Q81. What is wrong with this code?

const foo = {
  bar() {
    console.log('Hello, world!');
  },
  name: 'Albert',
  age: 26,
};
  1. The function bar needs to be defined as a key/value pair.
  2. Trailing commas are not allowed in JavaScript.
  3. Functions cannot be declared as properties of objects.
  4. Nothing, there are no errors.✔️

Q82. What will be logged to the console?

console.log('I');
setTimeout(() => {
  console.log('love');
}, 0);
console.log('Javascript!');
  1. A✔️
I
Javascript!
love
  1. B
love
I
Javascript!
  1. The output may change with each execution of code and cannot be determined.
  2. D
I
love
Javascript!

Q83. What will this code log to the console?

const foo = [1, 2, 3];
const [n] = foo;
console.log(n);
  1. 1✔️
  2. undefined
  3. NaN
  4. Nothing–this is not proper JavaScript syntax and will throw an error.

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

const foo = {
  name: 'Albert',
};
  1. delete name from foo;
  2. delete foo.name;✔️
  3. del foo.name;
  4. remove foo.name;

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

  1. There is no difference.
  2. The forEach() method returns a single output value, wheras the map() method performs operation on each value in the array.
  3. The map() methods returns a new array with a transformation applied on each item in the original array, wheras the forEach() method iterates through an array with noreturn value.✔️
  4. The forEach() methods returns a new array with a transformation applied on each item in the original array, wheras the map() method iterates through an array with noreturn value.

Q86. Which concept does this code illustrate?

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

var addFive = makeAdder(5);
console.log(addFive(3));
  1. overloading
  2. closure
  3. currying✔️
  4. overriding

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

  1. <script></script>✔️
  2. <js></js>
  3. <javascript></javascript>
  4. <code></code>

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

for (var i = 0; i < 5; i++) {
  console.log(i);
}
  1. 0 1 2 3 4✔️
  2. 0 1 2 3 4 5
  3. 1 2 3 4
  4. 1 2 3 4 5

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';
  1. pie
  2. fruit✔️
  3. undefined
  4. pudding

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?

  1. Security-Mode
  2. Access-Control-Allow-Origin✔️
  3. Different-Origin
  4. Same-Origin

Explanation:

Q91. What will be logged to the console?

'use strict';
function logThis() {
  this.desc = 'logger';
  console.log(this);
}
new logThis();
  1. window
  2. undefined
  3. function
  4. {desc: “logger”}✔️

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

  1. defer causes the script ta be loaded from the backup content delivery network (CDN).
  2. defer allows the browser ta continue processing the page while the script loads in the background.✔️
  3. defer blacks the browser from processing HTML below the tag until the script is completely loaded.
  4. defer lazy loads the script, causing it to download only when it is called by another script on the page.

Q93. 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
  1. animals.filter(e => e === “jaguar”);
  2. animals.reverse();✔️
  3. animals.shift();
  4. animals.pop();✔️

Reference Javascript Array Reverse

Q94. 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
}
  1. let vowels = “aeiou”.toArray();
  2. let vowels = Array.of(“aeiou”);
  3. let vowels = {“a”, “e”, “i”, “o”, “u”};
  4. let vowels = “aeiou”;✔️

Q95. What will be logged to the console?

const x = 6 % 2;
const y = x ? 'One' : 'Two';
console.log(y);
  1. undefined
  2. One
  3. true
  4. Two✔️

Reference ternary operator js

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

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

  1. matrix[1[2]]
  2. matrix[1][1]✔️
  3. matrix[1,2]
  4. matrix[1][2]

Q97. What does this code do?

const animals = ['Rabbit', 'Dog', 'Cat'];
animals.unshift('Lizard');
  1. It adds “Lizard” to the start of the animals array.✔️
  2. It adds “Lizard” to the end of the animals array.
  3. It replaces “Rabbit” with “Lizard” in the animals array.
  4. It replaces “Cat” with “Lizard” in the animals array.

Q98. What is the output of this code?

let x = 6 + 3 + '3';
console.log(x);
  1. 93✔️
  2. 12
  3. 66
  4. 633

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

  1. else
  2. when
  3. if
  4. switch✔️

Reference switch

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

var sound = 'grunt';
var bear = { sound: 'roar' };
function roar() {
  console.log(this.sound);
}
  1. bear.bind(roar);
  2. roar.bind(bear);
  3. roar.apply(bear);✔️
  4. bear{roar}();

Reference Apply

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

  1. a, b => { return c; }
  2. a, b => c
  3. { a, b } => c
  4. (a,b) => c✔️

Reference arrow functions

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

export const printMe = (str) => console.log(str);

  1. import printMe from ‘./some-file’;
  2. import { printMe } from ‘./some-file’;✔️
  3. import default as printMe from ‘./some-file’;
  4. const printMe = import ‘./some-file’;

Reference importing libraries in javascript

Q103. What will be the output of this code?

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

console.log([...arr1, ...arr2]);
  1. [2, 3, 4, 5, 6, 7]
  2. [3,5,7,2,4,6]
  3. [3, 5, 7, 2, 4, 6]
  4. [[2, 4, 6], [3, 5, 7]]
  5. [2, 4, 6, 3, 5, 7]✔️

Reference spread syntax

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

  1. done()
  2. then()✔️
  3. finally()
  4. catch()

Reference fetch

Q105. Which choice is not an array method?

  1. array.slice()
  2. array.shift()
  3. array.push()
  4. array.replace()✔️

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

  1. do…while✔️
  2. forEach
  3. while
  4. for

Reference loops in js

Q107. What will be logged to the console?

console.log(typeof ‘blueberry’);

  1. string✔️
  2. array
  3. Boolean
  4. object

Reference what is typeof

Q108. 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. C B A✔️
  2. A
  3. C
  4. A B C

Reference query selector Reference events

Q109. 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));
  1. [4,5,6,7,8,9,10]
  2. [4,5,6,7]
  3. [1,2,3,4,5,6]
  4. [4,5,6]✔️

Q110. 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);
  1. 2
  2. 4
  3. 6✔️
  4. 8

Reference MDN JavaScript Looping code

Q111. 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
  1. A
for (let key of cipherText.keys()) {
  plainText += key % 2 === 0 ? key : ' ';
}
  1. B
for (let [index, value] of cipherText.entries()) {
  plainText += index % 2 !== 0 ? value : '';
}
  1. C✔️
for (let [index, value] of cipherText.entries()) {
  plainText += index % 2 === 0 ? value : '';
}
  1. D
for (let value of cipherText) {
  plainText += value;
}

Reference MDN JavaScript Destructuring

Q112. Which Pokemon will be logged to the console?

var pokedex = ['Snorlax', 'Jigglypuff', 'Charmander', 'Squirtle'];
pokedex.pop();
console.log(pokedex.pop());
  1. Charmander✔️
  2. Jigglypuff
  3. Snorlax
  4. Squirtle

Reference Array.pop

Q113. 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>
  1. document.querySelector(“div.content”)
  2. document.querySelector(“span.content”)✔️
  3. document.querySelector(“.content”)
  4. document.querySelector(“div.span”)

Q114. Which value is not falsey?

  1. []✔️
  2. undefined
  3. 0
  4. null

Reference Falsy

Q115. 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. line 5, because lion cannot be reassigned a value✔️
  2. line 6, because the += operator cannot be used with the undefined variable bear
  3. line 5, because the prefix (++) operator does not exist in JavaScript
  4. line 3, because the variable bear is left undefined

Reference const in js

Q116. 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. It will throw a TypeError.
  2. [“Name”, “Age”, “HairColor”]
  3. [“DAVE”, 40, “BLUE”]
  4. [“NAME”, “AGE”, “HAIRCOLOR”]✔️

Reference Object.keys()

Q117. 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");
}
  1. animals.every(key)
  2. animals.some(key).length === 1
  3. animals.filter(key) === true
  4. animals.some(key)✔️

Reference Array.prototype.some

Q118. What is the output of this code?

class RainForest {
  static minimumRainFall = 60;
}

let congo = new RainForest();
RainForest.minimumRainFall = 80;
console.log(congo.minimumRainFall);
  1. undefined✔️
  2. None of these answers, as static is not a feature in Javascript.
  3. 60
  4. 80

Reference Classes static

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

let obj = {};

  1. obj?.a.b
  2. obj.a?.b✔️
  3. obj[a][b]
  4. obj.?a.?b

Reference Optional chaining (?.)

Q120. What happens when you run this code?

if (true) {
  var x = 5;
  const y = 6;
  let z = 7;
}
console.log(x + y + z);
  1. It will throw a ReferenceError about x.
  2. It will print 18.
  3. It will print undefined.
  4. It will throw a ReferenceError about y.✔️

Reference let statement

Q121. What does this code print to the console?

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

Reference spread syntax (…)

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

const a = { x: 1 };
const b = { x: 1 };
  1. a[‘x’] === b[‘x’]
  2. a != b
  3. a === b✔️
  4. a.x === b.x

Q123. What will this code log to the console?

console.log(typeof 41.1);

  1. Nothing. It resuults in a ReferenceError.
  2. decimal
  3. float
  4. number✔️

Reference

Q124. 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. 3
  2. 4✔️
  3. 6
  4. 7

Reference Array.prototype.push()

Q125. 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();
  1. Nothing is printed to the console.
  2. grunt
  3. undefined✔️
  4. roar

Reference

Q126. 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);
  1. undefined
  2. Wild✔️
  3. Tabby
  4. Athena

Q127. What will this code output to the log?

var thing;
let func = (str = 'no arg') => {
  console.log(str);
};
func(thing);
func(null);
  1. null no arg
  2. no arg no arg
  3. null null
  4. no arg null✔️

Q128. 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();
  1. a is 1
  2. a is undefined
  3. It won’t print anything.
  4. a is 2✔️

Q129. 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);
  1. 8✔️
  2. 6
  3. 2
  4. 12

Q130. 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);
  1. flagDatabase.countries[1].flag
  2. flagDatabase.countries[0].flag✔️
  3. flagDatabase[1].flag
  4. flagsJSON.countries[0].flag

Q131. Which snippet allows the acresOfRainForest variable to increase?

let conservation = true;
let deforestation = false;
let acresOfRainForest = 100;
if (/* Snipped goes here */){
    ++acresOfRainForest;
}
  1. conservation && !deforestation✔️
  2. !deforestation && !conservation
  3. !conservation || deforestation
  4. deforestation && conservation || deforestation

Q132. Which of these evaluate to true?

  1. Boolean(“false”)✔️
  2. Boolean(“”)
  3. Boolean(0)
  4. Boolean(NaN)

Q133. Which method converts a JSON string to a Javascript object?

  1. JSON.parse()✔️
  2. JSON.fromString();
  3. JSON.stringify()
  4. JSON.toObject()

Q134. Which method do you use to attach one DOM mode to another?

  1. attachNode()
  2. appendChild()✔️
  3. querySelector()
  4. getNode()

Q135. How would you add a data item named animal with a value of sloth to local storage for the current domain?

  1. LocalStorage.setItem(“animal”,”sloth”);
  2. document.localStorage.setItem(“animal”,”sloth”);✔️
  3. localStorage.setItem({animal:”sloth”});
  4. localStorage.setItem(“animal”,”sloth”);

Q136. 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);
  1. tiger large
  2. lion undefined
  3. undefined large✔️
  4. lion large

Q137. 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]);
  1. bear bear tiger sheep✔️
  2. lion bear sheep sheep
  3. bear bear tiger tiger
  4. lion bear tiger sheep

Q138. What will be the output of the following code.

a=5;
b=4;
alert(a++(+(+(+b))));
  1. 18
  2. 10
  3. 9✔️
  4. 20

Q139. What fragment could you add to this code to make it output “{“type”: “tiger”}” to the console?

let cat = { type: "tiger", size: "large" };

let json = /* Snippet here */;

console.log(json); // print {"type":"tiger"}
  1. cat.toJSON(“type”);
  2. JSON.stringify(cat, [“type”]);✔️
  3. JSON.stringify(cat);
  4. JSON.stringify(cat, /type/);

Q140. Which document method is not used to get a reference to a DOM node?

  1. document.getNode();✔️
  2. document.getElementsByClassName();
  3. document.querySelectorAll();
  4. document.querySelector();

Reference

Q141. 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); //prints {"type": "tiger"}
  1. JSON.sringify(cat);
  2. JSON.sringify(cat, [“type”]);✔️
  3. JSON.sringify(cat, /type/);
  4. cat.toJSON(“type”);

Q142. In JavaScript, all objects inherit a built-in property from a ___.

  1. node
  2. instance variable
  3. prototype✔️
  4. accessor

Q143. Which of the following are not server-side Javascript objects?

  1. Date
  2. FileUpload
  3. Function
  4. All of the above✔️

Q144. What will be the output of the following code snippet?

const obj1 = { first: 20, second: 30, first: 50 };
console.log(obj1);
  1. first: 30 , second: 50
  2. first: 50 , second: 30✔️
  3. first: 30 , second: 20
  4. None of the above

Q145. Which object in Javascript doesn’t have a prototype?

  1. Base Object✔️
  2. All objects have prototype
  3. None of the objects have prototype
  4. None of the above

Q146. What does __ operator do in JS?

  1. Used to spread iterables to individual elements✔️
  2. Describe datatype of undefined
  3. No such operator exists
  4. None of the above

Q147. How to stop an interval timer in Javascript?

  1. clearInterval✔️
  2. clearTimer
  3. intervalOver
  4. None of the above

Q148. What will be the output of the following code snippet?

print(typeof NaN);

  1. Object
  2. Number✔️
  3. String
  4. None of the above

Q149. What will be the output of the following code snippet?

<script type=”text/javascript”>a = 5 + “9”; document.write(a);</script>

  1. Compilation Error
  2. 14
  3. Runtime Error
  4. 59✔️

Q150. Which of the following methods can be used to display data in some form using Javascript?

  1. document.write()
  2. console.log()
  3. window.alert()
  4. all of the above✔️

Q151. 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
  1. a.prototype.belly[0]
  2. Object.getPrototype0f (a).belly[0]
  3. Animal.belly[0]✔️
  4. a.belly[0]

Reference Javascript Class static Keyword

Q152. What is the output of this code?

let rainForests = ['Amazon', 'Borneo', 'Cerrado', 'Congo'];
rainForests.splice(0, 2);
console.log(rainForests);
  1. [“Amazon”,”Borneo”,”Cerrado”,”Congo”]
  2. [“Cerrado”, “Congo”]✔️
  3. [“Congo”]
  4. [“Amazon”,”Borneo”]

Reference array methods

Q153. 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];

  1. const [one,two,three,four,five]=numbers✔️
  2. const {one,two,three,four,five}=numbers
  3. const [one,two,three,four,five]=[numbers]
  4. const {one,two,three,four,five}={numbers}

Reference array destructuring

Q154. What will this code print?

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

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

console.log(obj2.a, obj2.b);
  1. Nothing, it will throw an error
  2. 0 2✔️
  3. undefined 2
  4. undefined 2

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top