WorksheetsJS-Exam
Total questions: 56
Worksheet time: 31mins
1.Given the following code:
document.body.addEventListener(‘ click ’, (event) => {
if (/* CODE REPLACEMENT HERE */) { console.log(‘button clicked!’); )
});
Which replacement for the conditional statement on line 02 allows a developer to correctly determine that a button on page is clicked?
Event.clicked
e.nodeTarget ==this
event.target.nodeName == ‘BUTTON’
button.addEventListener(‘click’)
function Tiger() {
this.Type = 'Cat';
this.size = 'large';
}
let tony = new Tiger();
tony.roar = () => { console.log('Theyre great1'); };
function Lion() {
this.type = 'Cat';
this.size = 'large';
}
17 //Insert code here
18// leo.roar();
Which two statements could be inserted at line 17 to enable the function call on line 18? Choose 2 answers.
leo.roar = () => { console.log(‘They\’re pretty good:’); };
Object.assign(leo,Tiger);
Object.assign(leo,tony);
Leo.prototype.roar = () => { console.log(‘They\’re pretty good:’); };
4. Consider type coercion, what does the following expression evaluate to?
True + 3 + ‘100’ + null
104
4100
‘3100null’
‘4100null’
// 5. Refer to the code below
const pi = 3.1415326;
// What is the data type of pi?
Double
Number
Decimal
Float
// 7. Which statement parses successfully?
JSON. parse ('"foo"')
JSON.parse (""foo'")
JSON.parse ("foo");
JSON.parse ("foo");
10. Given two expressions var1 and var2. What are two valid ways to return the logical AND of the two expressions and ensure it is data type Boolean? Choose 2 answers:
Boolean(var1 && var2)
var1 && var2
var1.toBoolean() && var2toBoolean()
Boolean(var1) && Boolean(var2)
11. A developer has an ErrorHandler module that contains multiple functions. What kind of export leverages so that multiple functions can be used?
Named
All
Multi
Default
// 15. Refer to the code snippet below:
let array = [1, 2, 3, 4, 4, 5, 4, 4];
for (let i =0; i < array.length; i++){
if (array[i] === 4) {
array.splice(i, 1);
}}
[1, 2, 3, 4, 5, 4, 4]
[1, 2, 3, 4, 4, 5, 4]
[1, 2, 3, 4, 5, 4]
[1, 2, 3, 5]
16. Refer to the code below: let str = ‘javascript’; str[0] = ‘J’; str[4] = ’S’;
After changing the string index values, the value of str is ‘javascript’.
What is the reason for this value:
Non-primitive values are mutable.
Non-primitive values are immutable.
Primitive values are mutable.
Primitive values are immutable.
18. The developer wants to test the array shown:
const arr = Array(5).fill(0)
Which two tests are the most accurate for this array? Choose 2 answers:
console.assert( arr.length === 5 );
arr.forEach(elem => console.assert(elem === 0))
console.assert(arr[0] === 0 && arr[ arr.length] === 0);
console.assert (arr.length >0);
19. Which two console logs outputs NaN? Choose 2 answers
console.log(10/ Number(‘5’));
console.log(parseInt(‘two’));
console.log(10/ ‘five');
console.log(10/0);
22. A developer wants to leverage a module to print a price in pretty format, and has imported a method as shown below:
Import printPrice from ‘/path/PricePrettyPrint.js’;
Based on the code, what must be true about the printPrice function of the PricePrettyPrint module for this import to work?
printPrice must be be a named export
printPrice must be an all export
printPrice must be the default export
printPrice must be a multi export
// 23. Refer to the code below:
console.log('start');
Promise.resolve('Success').then(function(value){ console.log('Success');
});
console.log('End');
// What is the output after the code executes successfully?
End Start Success
Start Success End
Start End Success
Success Start End
26. Refer to HTML below: <div id =”main”> <div id = “ card-00”>This card is smaller.</div> <div id = “card-01”>
The width and height of this card is determined by its contents.</div> </div> Which expression outputs the screen width of the element with the ID card-01?
document.getElementById(‘ card-01 ’).getBoundingClientRest().width
document.getElementById(‘ card-01 ’).style.width
document.getElementById(‘ card-01 ’).width
document.getElementById(‘ card-01 ’).innerHTML.length
27. A developer creates an object where its properties should be immutable and prevent properties from being added or modified. Which method should be used to execute this business requirement?
Object.const()
Object.eval()
Object.lock()
Object.freeze()
30. Which three browser specific APIs are available for developers to persist data between page loads? Choose 3 answers
A. IIFEs
B. indexedDB
Global variables
Cookies
localStorage.
34. Refer to code below:
Let productSKU = ‘8675309’ ;
A developer has a requirement to generate SKU numbers that are always 19 characters long, starting with ‘sku’, and padded with zeros.
Which statement assigns the values sku 0000000008675309?
productSKU = productSKU .padStart (19. ‘0’).padstart(‘sku’);
productSKU = productSKU .padEnd (16. ‘0’).padstart(‘sku’);
productSKU = productSKU .padEnd (16. ‘0’).padstart(19, ‘sku’);
productSKU = productSKU .padStart (16. ‘0’).padstart(19, ‘sku’);
35. Refer to HTML below:
<p> The current status of an Order: <span id =”status”> In Progress </span> </p>.
Which JavaScript statement changes the text ‘In Progress’ to ‘Completed’?
document.getElementById(“status”).Value = ’Completed’;
document.getElementById(“#status”).innerHTML = ’Completed’ ;
document.getElementById(“status”).innerHTML = ’Completed’ ;
document.getElementById(“.status”).innerHTML = ’Completed’ ;
46. developer has a web server running with Node.js. The command to start the web server is node server,js. The web server started having latency issues. Instead of a one second turn around for web requests, the developer now sees a five second turnaround, Which command can the web developer run to see what the module is doing during the latency period?
DEBUG = http, https node server.js
NODE_DEBUG =http, https node server.js
DEBUG =true node server.js
NODE_DEBUG =true node server.js
51. Refer to the code below:
let sayHello = () => { console.log ('Hello, world!'); };
Which code executes sayHello once, two minutes from now?
setTimeout(sayHello, 12000);
setInterval(sayHello, 12000);
setTimeout(sayHello(), 12000);
delay(sayHello, 12000);
52. Which three statements are true about promises?
Choose 3 answers
The executor of a new Promise runs automatically.
A Promise has a .then() method.
A fulfilled or rejected promise will not change states .
A settled promise can become resolved.
A pending promise can become fulfilled, settled, or rejected.
56. A developer has a formatName function that takes two arguments, firstName and lastName and returns a string. They want to schedule the function to run once after five seconds. What is the correct syntax to schedule this function?
setTimeout (formatName(), 5000, "John", "BDoe");
setTimeout (formatName('John', ‘'Doe'), 5000);
setTimout(() => { formatName("John', 'Doe') }, 5000);
setTimeout (formatName, 5000, 'John", "Doe');
57. A developer wants to create an object from a function in the browser using the code below:
function Monster() { this.name = 'hello' };
Line 2: const z = Monster();
What happens due to lack of the new keyword on line 02
The z variable is assigned the correct object.
The z variable is assigned the correct object but this.name remains undefined.
Window.name is assigned to ‘hello’ and the variable z remains undefined.
Window.m is assigned the correct object.
61. A developer is working on an ecommerce website where the delivery date is dynamically calculated based on the current day. The code line below is responsible for this calculation. Const deliveryDate = new Date ();
Due to changes in the business requirements, the delivery date must now be today’s
date + 9 days.
Which code meets this new requirement?
deliveryDate.setDate(( new Date ( )).getDate () +9);
deliveryDate.setDate( Date.current () + 9);
deliveryDate.date = new Date(+9) ;
deliveryDate.date = Date.current () + 9;
71. Universal Container (UC) just launched a new landing page, but users complain that the website is slow. A developer found some functions that cause this problem. To verify this, the developer decides to do everything and log the time each of these three suspicious functions consumes. console.time(‘Performance’);
maybeAHeavyFunction(); thisCouldTakeTooLong(); orMaybeThisOne(); console.endTime(‘Performance’);
Which function can the developer use to obtain the time spent by every one of the three functions?
console.timeLog()
console.getTime()
console.trace()
console.timeStamp()
72. Refer to code below:
Let first = ‘who’; Let second = ‘what’; Try{
Try{ Throw new error(‘Sad trombone’); }catch (err){ First =’Why’; }finally { Second =’when’; } catch (err) { Second =’Where’; } What are the values for first and second once the code executes?
First is Who and second is When
First is why and second is where
First is who and second is where
First is why and second is when
77. Teams at Universal Containers (UC) work on multiple JavaScript projects at the same time.
UC is thinking about reusability and how each team can benefit from the work of others. Going open-source or public is not an option at this time. Which option is available to UC with npm?
Private packages can be scored, and scopes can be associated to a private registries.
Private registries are not supported by npm, but packages can be installed via URL.
Private packages are not supported, but they can use another package manager like yarn.
Private registries are not supported by npm, but packages can be installed via git.
79. Which option is a core Node.js module?
Path
Ios
Memory
locate
91. In which situation should a developer include a try .. catch block around their function call?
The function has an error that should not be silenced.
The function results in an out of memory issue.
The function might raise a runtime error that needs to be handled.
The function contains scheduled code.
94. A developer is debugging a web server that uses Node.js The server hits a runtimeerror every third request to an important endpoint on the web server. The developer added a break point to the start script, that is at index.js at he root of the server’s source code.
The developer wants to make use of chrome DevTools to debug.
Which command can be run to access DevTools and make sure the breakdown is hit?
node -i index.js
Node --inspect-brk index.js
Node inspect index.js
Node --inspect index.js
97. Which statement can a developer apply to increment the browser's navigation history without a page refresh? Which statement can a developer apply to increment the browser's navigation history without a page refresh?
window.history.pushState(newStateObject);
window.history.pushStare(newStateObject, '', null);
window.history.replaceState(newStateObject,'', null);
window.history.state.push(newStateObject);
99. Refer to the code below:
function Person(firstName, lastName, eyeColor) {
this.firstName =firstName;
this.lastName = lastName;
this.eyeColor = eyeColor;
}
Person.job = ‘Developer’;
const myFather = new Person(‘John’, ‘Doe’);
console.log(myFather.job);
ReferenceError: eyeColor is not defined
ReferenceError: assignment to undeclared variable “Person”
Developer
Undefined
100. Which statement accurately describes the behaviour of the async/ await keywords?
The associated class contains some asynchronous functions.
The associated function will always return a promise
The associated function can only be called via asynchronous methods
The associated sometimes returns a promise.
101. A developer wants to use a module named universalContainersLib and then call functions from it. How should a developer import every function from the module and then call the functions foo and bar?
import * from '/path/universalContainersLib.js'; universalContainersLib. foo ()
import {foo,bar} from '/path/universalCcontainersLib.js'; foo(): bar()?
import all from '/path/universalContainersLib.js'; universalContainersLib.foo(); universalContainersLib.bar ();
import * as lib from '/path/universalContainersLib.js';
lib.foo();
lib. bar ();
105. Which javascript methods can be used to serialize an object into a string and deserialize a JSON string into an object, respectively?
JSON.stringify and JSON.parse
JSON.serialize and JSON.deserialize
JSON.encode and JSON.decode
JSON.parse and JSON.deserialize
106. Which function should a developer use to repeatedly execute code at a fixed interval?
setIntervel
setTimeout
setPeriod
setInteria
107. Refer to the code below:
function foo () {
const a =2; function bat() {
console.log(a);
} return bar; }
Why does the function bar have access to variable a ?
Inner function’s scope
Hoisting
Outer function’s scope
Prototype chain
114. Refer to the following array: Let arr = [ 1,2, 3, 4, 5];
Which three options result in x evaluating as [3, 4, 5]? Choose 3 answers.
Let x= arr.filter (( a) => (a<2));
Let x= arr.splice(2,3);
Let x= arr.slice(2);
Let x= arr.filter((a) => ( return a>2 ));
Let x = arr.slice(2,3);
115. Given the code below: const copy = JSON.stringify([ new String(‘ false ’), new Boolean( false ), undefined ]); What is the value of copy?
[ \”false\” , { } ]--
[ false, { } ]--
[ \”false\” , false, undefined ]-
-- [ \”false\” ,false, null ]--
118. Refer to code below:
function muFunction(reassign){
Let x = 1; var y = 1;
if( reassign ) {
Let x= 2; Var y = 2;
console.log(x); console.log(y);
}
console.log(x); console.log(y);
}
What is displayed when myFunction(true) is called?
2 2 1 1
2 2 undefined undefined
2 2 1 2
2 2 2 2
120. Given the following code:
let x =(‘15’ + 10)*2;
What is the value of x?
A. 3020
1520
50
35
123. A developer implements and calls the following code when an application state change occurs: Const onStateChange =innerPageState) => { window.history.pushState(newPageState, ‘ ’, null); }
If the back button is clicked after this method is executed, what can a developer expect?
A navigate event is fired with a state property that details the previous application state.
The page is navigated away from and the previous page in the browser’s history is loaded.
The page reloads and all Javascript is reinitialized.
A popstate event is fired with a state property that details the application’s last state.
124. Refer to the code below:
let timeFunction =() => { console.log(‘Timer called.”); };
let timerId = setTimeout (timedFunction, 1000); Which statement allows a developer to cancel the scheduled timed function?
removeTimeout(timedFunction);
removeTimeout(timerId);
clearTimeout(timerId);
clearTimeout(timedFunction);
126. A developer writers the code below to calculate the factorial of a given number.
function factorial(number) { return number + factorial(number -1);
}
factorial(3);
What is the result of executing line 04?
0
6
-Infinity
RuntimeError
130. Given a value, which three options can a developer use to detect if the value is NaN?
Choose 3 answers
value == NaN
Object.is(value, NaN)
value === Number.NaN
value ! == value
Number.isNaN(value)
131. Which three actions can be using the JavaScript browser console?
Choose 3 answers:
A. View and change DOM the page.
Display a report showing the performance of a page.
Run code that is not related to page.
view , change, and debug the JavaScript code of the page.
View and change security cookies.
132. Considering type coercion, what does the following expression evaluate to? True + ‘13’ + NaN
‘ 113Nan ’
14
‘ true13 ’
‘ true13NaN ’
135. A developer receives a comment from the Tech Lead that the code given below has error:
const monthName = ‘July’; const year = 2019; if(year === 2019) {
monthName = ‘June’; }
Which line edit should be made to make this code run?
let monthName =’July’;
let year =2019;
const year = 2020;
if (year == 2019) {
139. A developer is wondering whether to use, Promise.then or Promise.catch, especially when a Promise throws an error? Which two promises are rejected? Which 2 are correct?
Promise.reject(‘cool error here’).then(error => console.error(error));
Promise.reject(‘cool error here’).catch(error => console.error(error));
New Promise((resolve, reject) => (throw ‘cool error here’}).catch(error => console.error(error)) ;
New Promise(() => (throw ‘cool error here’}).then(null, error => console.error(error)));
140. Given the code below:
Function myFunction(){ A =5; Var b =1; }
myFunction();
//Line 8: console.log(a);
//Line 9: console.log(b);
What is the expected output?
Both lines 08 and 09 are executed, and the variables are outputted.
Line 08 outputs the variable, but line 09 throws an error.
Line 08 thrones an error, therefore line 09 is never executed.
Both lines 08 and 09 are executed, but values outputted are undefined.
156. Given the following code:
Let x =null; console.log(typeof x);
What is the output of the line 02?
“Null”
“X”
“Object”
“undefined”
157. Which option is true about the strict mode in imported modules?
Add the statement use non-strict, before any other statements in the module to enable not-strict mode.
You can only reference notStrict() functions from the imported module.
Imported modules are in strict mode whether you declare them as such or not.
Add the statement use strict =false; before any other statements in the module to enable not- strict mode.
163. At Universal Containers, every team has its own way of copying JavaScript objects. The code Snippet shows an implementation from one team:
Function Person() { this.firstName = “John”;
this.lastName = ‘Doe’; This.name =() => ( console.log(‘Hello $(this.firstName) $(this.firstName)’);
)} Const john = new Person (); Const dan = JSON.parse(JSON.stringify(john)); dan.firstName =’Dan’; dan.name();
What is the Output of the code execution?
Hello Dan Doe
Hello John DOe
TypeError: dan.name is not a function
TypeError: Assignment to constant variable.
// 165: Refer to code below:
const objBook = {
Title: 'Javascript',};
Object.preventExtensions(objBook);
const newObjBook = objBook;
newObjBook.author = 'Robert';
// What are the values of objBook and newObjBook respectively?
[title: “javaScript”] [title: “javaScript”]
{author: “Robert”, title: “javaScript} Undefined
{author: “Robert”, title: “javaScript} {author: “Robert”, title: “javaScript}
{author: “Robert”} {author: “Robert”, title: “javaScript}
// 168 - What is the value of result?
function changeValue(param) {
param = 5;}
let a = 10; let b = a;
changeValue(b);
const result = a+ '-' + b;
10-10
5-5
10-5
5-10
// 169 Considering that JavaScript is single-threaded, what is the output of line 08 after the code executes?
let total = 10;
const interval = setInterval( () => {
total++ clearInterval(interval); total++;
}, 0)
total++;
10
11
12
13
