Linkedin-Skill-Assessments-Quizzes - Javascript-Quiz - MD at Main Ebazhanov - Linkedin-Skill-Assessments-Quizzes GitHub
Linkedin-Skill-Assessments-Quizzes - Javascript-Quiz - MD at Main Ebazhanov - Linkedin-Skill-Assessments-Quizzes GitHub
main
129 contributors
JavaScript
Q1. Which operator returns true if the two compared values are not equal?
<>
==!
!==
Q3. Review the code below. Which statement calls the addTax function and passes 50 as an
argument?
function addTax(total) {
return total * 1.05;
}
addTax = 50;
addTax 50;
Q4. Which statement is the correct way to create a variable called rate and assign it the value
100?
rate = 100;
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?
after 10 second
after results are received from the HTTP request
after 10000 seconds
immediately
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
a.prototype.belly[0]
Object.getPrototype0f (a).belly[0]
Animal.belly[0]
a.belly[0]
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?
1. Reference setTimeout
2. Reference immediately invoked anonymous functions
Reference
let discountPrice(price) {
return price * 0.85;
};
Storm()
undefined
'rain'
'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?
/[0-9]{2,}:[0-9]{2,}:[0-9]{2,}/
/\d\d:\d\d:\d\d/
/[0-9]+:[0-9]+:[0-9]+/
/ : : /
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
'use strict';
function logThis() {
this.desc = 'logger';
console.log(this);
}
new logThis();
undefined
window
{desc: "logger"}
function
Reference javascript classes
Q14. How would you reference the text 'avenue' in the code shown?
roadTypes.2
roadTypes[3]
roadTypes.3
roadTypes[2]
console.log(typeof 42);
'float'
'value'
'number'
'integer'
Q16. Which property references the DOM object that dispatched an event?
self
object
target
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)) {
}
}
JSON.fromString();
JSON.parse()
JSON.toObject()
JSON.stringify()
Q20. What would be the result in the console of running this code?
12345
1234
01234
012345
Q21. Which Object method returns an iterable that can be used to iterate over the properties
of an object?
Object.get()
Object.loop()
Object.each()
Object.keys()
101
3
4
100
Q23. What is one difference between collections created with Map and collections created
with Object?
pie
The code will throw an error.
pudding
undefined
Q25. 0 && hi
ReferenceError
true
0
false
++
--
==
||
Q27. Which statement sets the Person constructor as the parent of the Student constructor in
the prototype chain?
Student.parent = Person;
Student.prototype = Person;
Student.prototype = Person();
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?
all of them
const
var
let
Boolean(0)
Boolean("")
Boolean(NaN)
Boolean("false")
this
catch
function
array
Arguments
args
argsArray
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();
x.get('Y')
x.Y
x.Y()
x.get().Y
Reference getters
sum(10, 20);
diff(10, 20);
function sum(x, y) {
return x + y;
}
Q35. Why is it usually better to work with Objects instead of Arrays to store a collection of
records?
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?
import 'lodash' as _;
[] == [];
true
undefined
[]
false
Q39. What type of function can have its execution suspended and then resumed at a later
point?
Generator function
Arrow function
Async/ Await function
Promise function
var v = 1;
var f1 = function () {
console.log(v);
};
var f2 = function () {
var v = 2;
f1();
};
f2();
2
1
Nothing - this code will throw an error.
undefined
Q42. Your code is producing the error: TypeError: Cannot read property 'reduce' of undefined.
What does that mean?
You are calling a method named reduce on an object that's declared but has no value.
You are calling a method named reduce on an object that does not exist.
You are calling a method named reduce on an empty array.
You are calling a method named reduce on an object that's has a null value.
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?
3
2
0
1
delete
instanceof
void
Q45. What type of scope does the end variable have in the code shown?
var start = 1;
if (start === 1) {
let end = 2;
}
conditional
block
global
function
const x = 6 % 2;
const y = x ? 'One' : 'Two';
One
undefined
TRUE
Two
throw
exception
catch
error
Q48. What's one difference between the async and defer attributes of the HTML script tag?
var a;
var b = (a = 3) ? true : false;
Q50. Which statement references the DOM node created by the code shown?
Document.querySelector('class.pull')
document.querySelector('.pull');
Document.querySelector('pull')
Document.querySelector('#pull')
10
true
false
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);
10
0
ReferenceError
undefined
Reference
function sayHello() {
console.log('hello');
}
console.log(sayHello.prototype);
undefined
"hello"
an object with a constructor property
an error message
Reference prototypes
Q54. Which collection object allows unique value to be inserted only once?
Object
Set
Array
Map
function printA() {
console.log(answer);
var answer = 1;
}
printA();
printA();
1 then 1
1 then undefined
Reference
Q56. How does the forEach() method differ from a for statement?
forEach allows you to specify your own iterator, whereas for does not.
forEach can be used only with strings, whereas for can be used with additional data types.
forEach can be used only with an array, whereas for can be used with additional data types.
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?
=> ({})
=> {}
=> { return {};}
=> (({}))
to start tasks that might take some time without blocking subsequent tasks from executing
immediately
to ensure that tasks further down in your code are not initiated until earlier tasks have
completed
to make your code faster
to ensure that the call stack maintains a LIFO (Last in, First Out) structure
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.
[3] == [3]
3 == '3'
3 != '3'
3 === '3'
1. Reference booleans
2. Reference 2 - booleans
cancel()
stop()
preventDefault()
prevent()
Q62. Which method do you use to attach one DOM node to another?
attachNode()
getNode()
querySelector()
appendChild()
break
pass
skip
continue
(a,b) => c
a, b => c
{ 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?
class
generator function
map
proxy
! This is a comment
# This is a comment
\\ This is a comment
// 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?
TypeError
SystemError
SyntaxError
LogicError
create()
new()
constructor()
init()
let a = 5;
console.log(++a);
4
10
6
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,
);
e.blockReload();
button.preventDefault();
button.blockReload();
e.preventDefault();
Q72. Which statement selects all img elements in the DOM tree?
Document.querySelector('img')
Document.querySelectorAll('<img>')
Document.querySelectorAll('img')
Document.querySelector('<img>')
Q73. Why would you choose an asynchronous structure for your code?
Q74. What is the HTTP verb to request the contents of an existing resource?
DELETE
GET
PATCH
POST
focus
blur
hover
enter
function logThis() {
console.log(this);
}
logThis();
function
undefined
Function.prototype
window
Q78. Which class-based lifecycle method would be called at the same time as this effect
Hook?
useEffect(() => {
// do things
}, []);
componentWillUnmount
componentDidUpdate
render
componentDidMount
Reference
var obj;
console.log(obj);
{}
undefined
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;
}
}
calculate(50);
new TaxCalculator().calculate($50);
TaxCalculator.calculate(50);
new TaxCalculator().calculate(50);
const foo = {
bar() {
console.log('Hello, world!');
},
name: 'Albert',
age: 26,
};
[x]
I
Javascript!
love
[]
love
I
Javascript!
The output may change with each execution of code and cannot be determined.
[]
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.
1
undefined
NaN
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',
};
Q85. What is the difference between the map() and the forEach() methods on the Array
prototype?
There is no difference.
The forEach() method returns a single output value, whereas the map() method performs
operation on each value in the array.
The map() methods returns a new array with a transformation applied on each item in the
original array, whereas the forEach() method iterates through an array with no return
value.
The forEach() methods returns a new array with a transformation applied on each item in
the original array, whereas the map() method iterates through an array with no return value.
1. Reference map
2. Reference Differences between forEach and for loop
function makeAdder(x) {
return function (y) {
return x + y;
};
}
overloading
closure
currying
overriding
Reference currying
<script></script>
<js></js>
<javascript></javascript>
<code></code>
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?
Security-Mode
Access-Control-Allow-Origin
Different-Origin
Same-Origin
["Amazon","Borneo","Cerrado","Congo"]
["Cerrado", "Congo"]
["Congo"]
["Amazon","Borneo"]
Q91. 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 [one,two,three,four,five]=numbers
const {one,two,three,four,five}=numbers
const [one,two,three,four,five]=[numbers]
const {one,two,three,four,five}={numbers}
const obj = {
a: 1,
b: 2,
c: 3,
};
const obj2 = {
...obj,
a: 0,
};
console.log(obj2.a, obj2.b);
Q93. Which line could you add to this code to print "jaguar" to the console?
animals.reverse();
animals.shift();
animals.pop();
//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
}
const x = 6 % 2;
const y = x ? 'One' : 'Two';
console.log(y);
undefined
One
true
Two
Q96. How would you access the word It from this multidimensional array?
matrix[1[2]]
matrix[1][1]
matrix[1,2]
matrix[1][2]
let x = 6 + 3 + '3';
console.log(x);
93
12
66
633
else
when
if
switch
Reference switch
bear.bind(roar);
roar.bind(bear);
roar.apply(bear);
bear[roar]();
1. Reference Apply
2. Reference this
3. Reference bind
Q101. Which choice is a valid example of an arrow function, assuming c is defined in the outer
scope?
a, b => { return c; }
a, b => c
{ a, b } => c
(a,b) => c
//some-file.js
export const printMe = (str) => console.log(str);
console.log([...arr1, ...arr2]);
[2, 3, 4, 5, 6, 7]
[3,5,7,2,4,6]
[3, 5, 7, 2, 4, 6]
[2, 4, 6, 3, 5, 7]
Q104. Which method call is chained to handle a successful response returned by fetch() ?
done()
then()
finally()
catch()
Reference fetch
array.slice()
array.shift()
array.push()
array.replace()
Q106. Which JavaScript loop ensures that at least a singular iteration will happen?
do…while
forEach
while
for
Reference loops in js
console.log(typeof 'blueberry');
string
array
Boolean
object
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);
});
CBA
A
C
ABC
[4,5,6,7,8,9,10]
[4,5,6,7]
[1,2,3,4,5,6]
[4,5,6]
console.log(animals);
2
4
6
8
Q111. Which snippet could you add to this code to print "YOU GOT THIS" to the console?
/* Missing Snippet */
Charmander
Jigglypuff
Snorlax
Squirtle
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
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?
document.querySelector("div.content")
document.querySelector("span.content")
document.querySelector(".content")
document.querySelector("div.span")
[]
undefined
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++;
line 6, because the += operator cannot be used with the undefined variable bear
line 5, because the prefix (++) operator does not exist in JavaScript
1. Reference const in js
2. Reference TypeError: invalid assignment to const "x"
Q116. What will be the value of result after running this code?
1. Reference Object.keys()
2. Reference Array.prototype.map()
3. Reference String.prototype.toUpperCase()
Q117. Which snippet could you insert to this code to print "swim" to the console?
animals.every(key)
animals.some(key).length === 1
animals.some(key)
Reference Array.prototype.some
class RainForest {
static minimumRainFall = 60;
}
undefined
60
80
Q119. How can you attempt to access the property a.b on obj without throwing an error if a
is undefined?
obj?.a.b
obj.a?.b
obj[a][b]
obj.?a.?b
if (true) {
var x = 5;
const y = 6;
let z = 7;
}
console.log(x + y + z);
[2,7]
[2,1,7,5]
const a = { x: 1 };
const b = { x: 1 };
a != b
a === b
Reference
console.log(typeof 41.1);
decimal
float
number
Reference
1. Reference Array.prototype.push()
2. Reference Array.prototype.pop()
3. Reference Array.prototype.reduce()
let bear = {
sound: 'roar',
roar() {
console.log(this.sound);
},
};
bear.sound = 'grunt';
let bearSound = bear.roar;
bearSound();
grunt
undefined
roar
Reference
function swap(feline) {
feline.name = 'Wild';
feline = { name: 'Tabby' };
}
swap(cat);
console.log(cat.name);
undefined
Wild
Tabby
Athena
var thing;
let func = (str = 'no arg') => {
console.log(str);
};
func(thing);
func(null);
null no arg
no arg no arg
null null
no arg null
a is 1
a is undefined
It won't print anything.
a is 2
8
6
2
12
Q130. Which code would you use to access the Irish flag?
var flagsJSON =
'{ "countries" : [' +
'{ "country":"Ireland" , "flag":"🇮🇪" },' +
'{ "country":"Serbia" , "flag":"🇷🇸" },' +
'{ "country":"Peru" , "flag":"🇵🇪" } ]}';
flagDatabase.countries[1].flag
flagDatabase.countries[0].flag
flagDatabase[1].flag
flagsJSON.countries[0].flag
Q131. Which snippet allows the acresOfRainForest variable to increase?
Boolean("false")
Boolean("")
Boolean(0)
Boolean(NaN)
JSON.parse()
JSON.fromString();
JSON.stringify()
JSON.toObject()
Q134. Which method do you use to attach one DOM mode to another?
attachNode()
appendChild()
querySelector()
getNode()
Q135. How would you add a data item named animal with a value of sloth to local storage for
the current domain?
LocalStorage.setItem("animal","sloth");
document.localStorage.setItem("animal","sloth");
localStorage.setItem({animal:"sloth"});
localStorage.setItem("animal","sloth");
Reference
Q136. What value is printed to the console after this code execute?
let cat = Object.create({ type: 'lion' });
cat.size = 'large';
console.log(copyCat.type, copyCat.size);
tiger large
lion undefined
undefined large
lion large
Reference
clones[0].type = 'bear';
clones[1] = 'sheep';
console.log(animals[0].type, clones[0].type);
console.log(animals[1], clones[1]);
Reference
a=5;
b=4;
alert(a++(+(+(+b))));
18
10
9
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" };
cat.toJSON("type");
JSON.stringify(cat, ["type"]);
JSON.stringify(cat);
JSON.stringify(cat, /type/);
Q140. Which document method is not used to get a reference to a DOM node?
document.getNode();
document.getElementsByClassName();
document.querySelectorAll();
document.querySelector();
Reference
Q141. Which snippet could you add to this code to print "{"type": "tiger"}" to the console?
JSON.sringify(cat);
JSON.sringify(cat, ["type"]);
JSON.sringify(cat, /type/);
cat.toJSON("type");
Reference
node
instance variable
prototype
accessor
Reference
Date
FileUpload
Function
All of the above
first: 30 , second: 50
first: 50 , second: 30
first: 30 , second: 20
None of the above
Base Object
All objects have prototype
None of the objects have prototype
None of the above
clearInterval
clearTimer
intervalOver
None of the above
Reference
print(typeof NaN);
Object
Number
String
None of the above
Compilation Error
14
Runtime Error
59
Q150. Which of the following methods can be used to display data in some form using
Javascript?
document.write()
console.log()
window.alert()
all of the above