101) Refer to the 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 statement outputs the height of the element with the ID card-01?
- (document.getElementById(‘card-01’).innerHTML.length)/32)*6
- document.getElementById(‘card-01’).height
- document.getElementById(‘card-01’).getBoundingClientRect().height
- document.getElementById(‘card-01’).style.height
102) A developer creates a simple webpage with an input field. When a user enters text in the input field and clicks the button, the actual value of the field must be displayed in the console.
<!-- HTML code --> <input type="text" value="Hello" name="input"> <button type="button">Display</button> <!-- JavaScript code --> const button document.querySelector("button"); button.addEventListener('click', () => { const input = document.querySelector('input'); console.log(input.getAttribute('value')); )}:
When the user clicks the button, the output is always “Hello”. What needs to be done to make this code work as expected?
- Replace line 04 with console.log(input.value);
- Replace line 03 with const input = document.getElementByName(‘input’);
- Replace line 02 with button.addEventListener(“onclick”, function() {
- Replace line 02 with button.addCallback(“click”, function() {
103) A developer copied a JavaScript object:
function Person() { this.firstName = "John"; this.lastName = "Doe"; this.name = () => `${this.firstName), $(this.lastName}`; } const john = new Person(); const dan = Object.assign(john); dan.firstName = 'Dan';
How does the developer access dan’s firstName, lastName? Choose 2 answers.
- dan.name
- dan.name()
- dan.firstName + dan.lastName
- dan.firstName() + dan.lastName()
104) Refer to the code below:
flag(); function flag() { console.log('flag'); } const anotherFlag = () => { console.log('another flag'); } anotherFlag();
What is result of the code block?
- An error is thrown.
- The console logs only ‘flag’.
- The console logs ‘flag’ and ‘another flag’.
- The console logs ‘flag’ and then an error is thrown.
105) Refer to the code below:
const event = new CustomEvent ( //Missing code ); obj.dispatchEvent (event);
A developer needs to dispatch a custom event called update to send information about recordid.Which two options could a developer insert at the placeholder in line 02 to achieve this? Choose 2 answers
- ‘update’, ‘123abc’
- ‘update’, {
detail : {
recordId: ‘123abc’
}
} - ‘update’, {
recordId: ‘123abc’
} - {type: ‘update’, recordId: ‘123abc’}
106) A developer implements and calls the following code when an application state change occurs:
const onStateChange = (newPageState) => { window.history.pushState(newPageState, '' ,null); }
If the back button is clicked after this method is executed, what can a developer expect?
- The page is navigated away from and the previous page in the browser’s history is loaded.
- A popstate event is fired with a state property that details the application’s last state.
- A navigate event is fired with a state property that details the previous application state.
- The page reloads and all JavaScript is reinitialized.
107) Refer to the 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 value sku0000000008675309?
- productSKU = productSKU.padStart(16, ‘0’).padStart(19, ‘sku’);
- productSKU = productSKU.padEnd(16, ‘0’).padStart(‘sku’);
- productSKU = productSKU.padStart(19, ‘0’).padStart(‘sku’);
- productSKU = productSKU.padEnd(16, ‘0’).padStart (19, ‘sku’);
108) Refer to the code below:
function foo() { const a = 2; function bar() { console.log(a); } return bar; }
Why does the function bar have access to variable a?
- Hoisting
- Inner function’s scope
- Outer function’s scope
- Prototype chain
109) Refer to the following code:
function test(val) { if (val === undefined) { return 'Undefined value!'; } if (val === null) { return 'Null value!'; } } let x; test(x);
What is returned by the function call on line 11?
- Line 11 throws an error.
- ‘Undefined value!’
- ‘Null value!’
- undefined
110) Which JavaScript methods can be used to serialize an object into a string and deserialize a JSON string into an object, respectively?
- JSON.encode and JSON.decode
- JSON.stringify and JSON.parse
- JSON.serialize and JSON.deserialize
- JSON.parse and JSON.deserialize
111) Given the code block below:
function GameConsole(name) { this.name = name; } GameConsole.prototype.load = function(gamename) { console.log(`$(this.name} is loading a game: $(gamename)...`); } function Console16bit(name) { GameConsole.call(this, name); } Console16bit.prototype = Object.create(GameConsole.prototype); // insert code here console.log(`${this.name} is loading a cartridge game: ${gamename}...`); } const console16bit = new Console16bit('SNEGeneziz'); console16bit.load('Super Monic 3x Force');
What should a developer insert at line 11 to output the following message using the load method?
> SNEGeneziz is loading a cartridge game: Super Monic 3x Force…
- Console16bit.prototype.load(gamename)= function() {
- Console16bit.prototype.load(gamename) {
- Console16bit.prototype.load = function(gamename) {
- Console16bit = Object.create (GameConsole.prototype).load = function(gamename) {
112) Refer to the code below:
let a = 'a'; let b; // b = a; console.log(b);
What is displayed when the code executes?
- undefined
- ReferenceError: b is not defined
- null
- a
113) 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);
What is the output after the code executes?
- ReferenceError: eyeColor is not defined
- TypeError: invalid assignment to const variable Person
- undefined
- Developer
114) The developer has a function that prints “Hello” to an input name. To test this, the developer created a function that returns “World”. However, the following snippet does not print “Hello World”.
const sayHello = (name) => { console.log('Hello', name); }; const world = () => { return 'World'; }; sayHello(world);
What can the developer do to change the code to print “Hello World”?
- Change line 4 to function world() {
- Change line 2 to console.log(‘Hello’, name());
- Change line 7 to sayHello(world)();
- Change line 6 to }();
115) Refer to the following code:
<html lang="en"> <div class="outerDiv"> <button class="myButton">Click me!</button> </div> <script> function displayInnerMessage(ev) { console.log('Inner message.'); } function displayOuterMessage(ev) { console.log('Outer message.'); } window.onload = (event) => { document.querySelector('.outerDiv').addEventListener('click', displayOuterMessage, true); document.querySelector('.myButton').addEventListener('click', displayInnerMessage, true); }; </script> </html>
What will the console show when the button is clicked?
- Outer message.
- Inner message. Outer message.
- Inner message.
- Outer message. Inner message.
116) Considering type coercion, what does the following expression evaluate to?
true + '13' + NaN
- ‘true13NaN’
- 14
- ‘true13’
- ‘113NaN’
117) A developer wants to use a try…catch statement to catch any error that count Sheep () may throw and pass it to a handleError() function. What is the correct implementation of the try…catch?
- setTimeout(function() {
try {
count Sheep():
} catch(e) {
handleError (e);
}
}, 1000); - try {
countSheep();
} finally {
handleError(e);
} - try {
countSheep();
} handleError(e) {
catch(e);
} - try {
setTimeout(function() {
countSheep();
}, 1000);
} catch(e) {
handleError(e);
}
118) myArray, can have one level, two levels, or more levels.
Which statement flattens myArray when it can be arbitrarily nested?
- myArray.reduce((prev, curr) => prev.concat(curr), []);
- myArray.join(“,”).split(“,”);
- myArray.flat(Infinity);
- [].concat(… myArray);
119) Refer to the code below:
let total = 10; const interval = setInterval(() => { total++; clearInterval(interval); total++; ), 0); total++; console.log(total);
Considering that JavaScript is single-threaded, what is the output of line 08 after the code executes?
- 10
- 11
- 12
- 13
120) Which statement accurately describes the behavior of the async/await keywords?
- The associated function will always return a promise.
- The associated function can only be called via synchronous methods.
- The associated function needs to be configured to return a promise.
- The associated class must not contain asynchronous functions.
121) Refer to the following code that imports a module named Utils:
import (foo, bar) from /path/Utils.js'; foo(); bar();
Which two implementations of Utils.js export foo and bar such that the code above runs without error? Choose 2 answers
-
//FooUtils.js and BarUtils.js exist
import (foo) from /path/FooUtils.js’;
import (bar) from /path/BarUtils.js’;
export (foo, bar) -
const foo = () => { return ‘foo’; }
const bar = () => { return ‘bar’; }
export default foo, bar; -
const foo = () => { return ‘foo’; }
const bar () => { return ‘bar’; }
export (foo, bar) -
export default class {
foo() { return ‘foo’; }
bar() { return ‘bar’; }
}
122) Refer to the following code:
function Tiger(){ this.type = 'Cat'; this.size = 'large'; }; let tony = new Tiger(); tony.roar = () => { console.log('They\'re great1'); }; function Lion(){ this.type = 'Cat'; this.size = 'large'; } let leo = new Lion(); //Insert code here leo.roar();
Which two statements could be inserted at line 14 to enable the function call on line 15? Choose 2 answers.
- Leo.prototype.roar = () => {console.log(‘They\’re pretty good:’);};
- Leo.roar = () => {console.log(‘They\’re pretty good:’);};
- Object.assign(leo,Tiger);
- Object.assign(leo,tony);
123) 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;
124) A developer has the following array of student test grades:
let arr = [7, 8, 5, 8, 9];
The Teacher wants to double each score and then see an array of the students who scored more than 15 points. How should the developer implement the request?
- let arr1 = arr.filter((val) => (return val > 15)).map((num) => (return num *2));
- let arr1 = arr.mapBy((num) => (return num *2)).filterBy((val) => return val > 15));
- let arr1 = arr.map((num) => num*2).Filter((val) => val > 15);
- let arr1 = arr.map((num) => (num *2)).filterBy((val) => (val > 15));
125) A developer publishes a new version of a package with new features that do not break backward compatibility. The previous version number was 1.1.3. Following semantic versioning format, what should the new package version number be?
- 2.0.0
- 1.2.3
- 1.1.4
- 1.2.0
126) 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
127) A class was written to represent items for purchase in an online store, and a second class representing items that are on sale at a discounted price. The constructor sets the name to the first value passed in. The pseudocode is below:
There is a new requirement for a developer to implement a description method that will return a brief description for Item and SaleItem.
class Item { constructor(name, price) { //Constructor Implementation } } class SaleItem extends Item { constructor(name, price, discount) { //Constructor Implementation } } let regItem = new Item(‘Scarf’, 55); let saleItem = new SaleItem(‘Shirt’ 80, -1); Item.prototype.description = function() {return ‘This is a’ + this.name;} console.log(regItem.description()); console.log(saleItem.description()); SaleItem.prototype.description = function() {return ‘This is a discounted ’ + this.name;} console.log(regItem.description()); console.log(saleItem.description());
What is the output when executing the code above?
- This is a Scarf
Uncaught TypeError: saleItem.description is not a function
This is a Scarf
This is a discounted Shirt - This is a Scarf
This is a Shirt
This is a Scarf
This is a discounted Shirt - This is a Scarf
This is a Shirt
This is a discounted Scarf
This is a discounted Shirt - This is a Scarf
Uncaught TypeError: saleItem.description is not a function
This is a Shirt
This is a did counted Shirt
128) Refer to the code:
function Animal(size, type){ this.size = size || "small"; this.type = type || "Animal"; this.canTalk = false; } let Pet = function (size, type, name, owner){ Animal.call(this, size, type); this.name = name; this.owner = owner; } Pet.prototype = Object.create(Animal.prototype); let pet1 = new Pet(); console.log(pet1);
Given the code above, which three properties are set pet1? Choose 3 answers:
- Name
- canTalk
- Type
- Owner
- Size
129) Refer to the code below:
let greeting = "Goodbye"; let salutation = "Hello, hello, hello"; try { greeting = "Hello"; decodeURI("%%%"); //throws error salutation = "Goodbye"; } catch(err) { salutation = "I say hello"; } finally { salutation = "Hello, hello"; }
Line 05 causes an error. What are the values of greeting and Salutation once the code completes?
- Greeting is Hello and Salutation is Hello, Hello.
- Greeting is Goodbye and Salutation is Hello, Hello.
- Greeting is Goodbye and Salutation is I say hello.
- Greeting is Hello and Salutation is I say hello.
130) 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.
131) Refer to the code below:
let textValue = '1984';
Which code assignment shows a correct way to convert this string to an integer?
- let numberValue = Number(textValue);
- let numberValue = (Number)textValue;
- let numberValue = textValue.toInteger();
- let numberValue = Integer(textValue);
132) Why would a developer specify a package.json as a developed forge instead of a dependency?
- It is required by the application in production.
- It is only needed for local development and testing.
- Other requiredpackages depend on it for development.
- It should be bundled when the package is published.
133) A developer is setting up a new Node.js server with a client library that is built using events and callbacks. The library:
* Will establish aweb socket connection and handle receipt of messages to the server.
* Will be imported with require, and made available with a variable called ws.
The developer also wants to add error logging if a connection fails.
Given this info, which code segment shows the correct way to set up a client with two events that listen at execution time?
- ws.connect(() => {
console.log(‘Connected to client’);
}).catch((error) => {
console.log(‘ERROR’, error);
}); - ws.on(‘connect’, () => {
console.log(‘Connected to client’);
ws.on(‘error’, (error) => {
console.log(‘ERROR’, error);
});
}); - ws.on(‘connect’, () => {
console.log(‘Connected to client’);
});
ws.on(‘error’, (error) => {
console.log(‘ERROR’, error);
}); - try {
ws.connect(() => {
console.log(‘Connected to client’);
});
} catch(error) {
console.log(‘ERROR’, error);
}
134) Developer creates a new web server that uses Node.js. It imports a server library that uses events and callbacks for handling server functionality. The server library is imported with require and is made available to the code by a variable named server. The developer wants to log any issues that the server has while booting up.
Given the code and the information the developer has, which code logs an error at boost with an event?
- server.catch((server) => {console.log(‘ERROR’, error);});
- server.error((server) => {console.log(‘ERROR’, error);});
- server.on(‘error’, (error) => {console.log(‘ERROR’, error);});
- try{server.start();} catch(error) {console.log(‘ERROR’, error);}
135) Which codestatement below correctly persists an objects in local Storage?
- const setLocalStorage = (storageKey, jsObject) => {window.localStorage.setItem(storageKey, JSON.stringify(jsObject));}
- const setLocalStorage = (jsObject) => {window.localStorage.connectObject(jsObject));}
- const setLocalStorage = (jsObject) => {window.localStorage.setItem(jsObject);}
- const setLocalStorage = (storageKey, jsObject) => {window.localStorage.persist(storageKey, jsObject);}
136) A 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 turnaround 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?
- NODE_DEBUG=true node server.js
- DEBUG=http, https node server.js
- NODE_DEBUG=http,https node server.js
- DEBUG=true node server.js
137) Refer to the code below?
LetsearchString = ‘ look for this ’;
Which two options remove the whitespace from the beginning of searchString? Choose 2 answers.
- searchString.trimEnd();
- searchString.trimStart();
- trimStart(searchString);
- searchString.replace(/*\s\s*/, ‘’);
138) Which three options show valid methods for creating a fat arrowfunction? Choose 3 answers.
- x => {console.log(‘executed’);}
- [] => {console.log(‘executed’);}
- () => {console.log(‘executed’);}
- x,y,z => {console.log(‘executed’);}
- (x,y,z) => {console.log(‘executed ‘);}
139) Which two code snippets show working examples of a recursive function? Choose 2 answers.
- let countingDown = function(startNumber){
if(startNumber > 0) {
console.log(startNumber);
return countingDown(startNUmber);
} else {return startNumber;}
}; - function factorial(numVar){ if(numVar < 0) return; if(numVar === 0) return 1; return numVar -1; };
- const sumToTen = numVar => { if(numVar < 0) return; return sumToTen(numVar + 1); };
- const factorial = numVar => { if(numVar < 0) return; if(numVar === 0) return 1; return numVar*factorial(numVar – 1); };
140) A developer uses a parsed JSON string to work with user information as in the block below:
const userInformation = { "id" : "user-01", "email" : "user01@universalcontainers.demo", "age" : 25 }
Which two options access the email attribute in the object? Choose 2 answers.
- userInformation(email)
- userInformation.get(“email”)
- userInformation.email
- userInformation[“email”]
141) A developer wants to set up a secure web server with Node.js. The developer creates a directory locally called app-server, and the first file is app-server/index.js Without using any third-party libraries, what should the developer add to index.js to create the secure web server?
- const http = require(‘http’);
- const server = require(‘secure-server’);
- const tls = require(‘tls’);
- const https = require(‘https’);
142) The developer wants to test this code:
const toNumber = (strOrNum) => strOrNum;
Which two tests are most accurate for this code? Choose 2 answers.
- console.assert(toNumber(‘2’) === 2);
- console.assert(Number.isNaN(toNumber()));
- console.assert(toNumber(‘-3’) < 0);
- console.assert(toNumber() === NaN);
143) Refer to the expression below:
let x = ('1' + 2) == (6 * 2);
How should this expression be modified to ensure that evaluates to false?
- let x = (‘1’ + ‘2’) == (6 * 2);
- let x = (‘1’ + 2) == (6 * 2);
- let x = (1 + 2) == (‘6’ / 2);
- let x = (1 + 2) == (6 / 2);
144) A developer wrote a fizzbuzz function that when passed in a number, returns the following:
- ‘Fizz’ if the number is divisible by 3.
- ‘Buzz’ if the number is divisible by 5.
- ‘Fizzbuzz’ if the number is divisible by both 3 and 5.
- Empty string if the number is divisible by neither 3 or 5.
Which two test cases will properly test scenarios for the fizzbuzz function? Choose 2 answers.
- let res = fizzbuzz(5);
console.assert(res === ”); - let res = fizzbuzz(15);
console.assert(res === ‘fizzbuzz’); - let res = fizzbuzz(Infinity);
console.assert(res === ”); - let res = fizzbuzz(3);
console.assert(res === ‘buzz’);
145) 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);
146) 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()
147) A developer creates a new web server that uses Node.js. It imports a server library that uses events and callbacks for handling server functionality. The server library is imported with require and is made available to the code by a variable named server. The developer wants to log any issues that the server has while booting up.
Given the code and the information the developer has, which code logs an error at boost with an event?
- server.catch((server) => {
console.log(‘ERROR’, error);
}); - server.error((server) => {
console.log(‘ERROR’, error);
}); - server.on(‘error’, (error) => {
console.log(‘ERROR’, error);
}); - try {
server.start();
} catch(error) {
console.log(‘ERROR’, error);
}
148) Refer to the code below:
function vehicle(same, price) { this.name = name; this.price = price; } vehicle.prototype.priceinfo = function() { return `Cost of the ${this.name} is ${this.price}$`; } var ford = new vehicle('Ford Fiesta', '20,000');
Given the requirement to refactor the code above to JavaScript class format, which class definition is correct?
- class vehicle {
constructor(name, price) {
this.name = name;
this.price = price;
}
priceInfo() {
return `Cost of the ${this.name} is ${this.price}$`;
}
} - class vehicle {
vehicle(name, price) {
this.name = name;
this.price = price;
}
priceInfo() {
return `Cost of the ${this.name} is ${this.price}$`;
}
} - class vehicle {
constructor(name, price) {
name = name;
price = price;
}
priceInfo() {
return `Cost of the ${this.name} is ${this.price}$`;
}
} - class vehicle {
constructor() {
this.name = name;
this.price = price;
}
priceInfo() {
return `Cost of the ${this.name} is ${this.price}$`;
}
}
149) Which three browser specific APIs are available for developers to persist data between page loads? Choose 3 answers.
- global variables
- IIFEs
- localStorage
- cookies
- indexedDB
150) Refer to the code below:
class Student { constructor(name) { this.name = name; } takeTest() { console.log(`${this.name} got 70% on test.`); } } class BetterStudent extends Student { constructor(name) { super(name); this.name = 'Better student ' + name; } takeTest() { console.log(`${this.name} got 100% on test.`); } } let student = new BetterStudent('Jackie'); student.takeTest();
What is the console output?
- > Uncaught ReferenceError
- > Better student Jackie got 70% on test.
- > Better student Jackie got 100% on test.
- > Jackie got 70% on test.