A developer is creating a simple webpage with a button. When a user clicks this button
for the first time, a message is displayed.
The developer wrote the JavaScript code below, but something is missing. The
message gets displayed every time a user clicks the button, instead of just the first time.
01 function listen(event) {
02 alert ( ‘Hey! I am John Doe’) ;03 button.addEventListener (‘click’, listen);
Which two code lines make this code work as required?
Choose 2 answers
A.
On line 02, use event.first to test if it is the first execution.
B.
On line 04, use event.stopPropagation ( ),
C.
On line 04, use button.removeEventListener(‘ click” , listen);
D.
On line 06, add an option called once to button.addEventListener().
On line 04, use button.removeEventListener(‘ click” , listen);
On line 06, add an option called once to button.addEventListener().
Refer to the following code:
Let sampleText = ‘The quick brown fox jumps’;
A developer needs to determine if a certain substring is part of a string.
Which three expressions return true for the given substring ?
Choose 3 answers
A.
sampleText.includes(‘fox’);
B.
sampleText.includes(‘ quick ’, 4);
C.
sampleText.includes(‘ Fox ’, 3)
D.
sampleText.includes(‘ fox ’);
E.
sampleText.includes(‘ quick ’) !== -1;
sampleText.includes(‘ quick ’, 4);
sampleText.includes(‘ fox ’);
sampleText.includes(‘ quick ’) !== -1;
Given the code below:
Setcurrent URL ();
console.log(‘The current URL is: ‘ +url );
function setCurrentUrl() {
Url = window.location.href:What happens when the code executes?
A.
The url variable has local scope and line 02 throws an error.
B.
The url variable has global scope and line 02 executes correctly.
C.
The url variable has global scope and line 02 throws an error.
D.
The url variable has local scope and line 02 executes correctly.
The url variable has global scope and line 02 executes correctly.
A developer is required to write a function that calculates the sum of elements in an
array but is getting undefined every time the code is executed. The developer needs to find
what is missing in the code below.
Const sumFunction = arr => {
Return arr.reduce((result, current) => {
//
Result += current;
//
), 10);
);
Which option makes the code work as expected?
A.
Replace line 02 with return arr.map(( result, current) => (
B.
Replace line 04 with result = result +current;
C.
Replace line 03 with if(arr.length == 0 ) ( return 0; )
D.
Replace line 05 with return result;
Replace line 05 with return result;
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?
A.
Server.catch ((server) => {
console.log(‘ERROR’, error);
});
B.
Server.error ((server) => {
console.log(‘ERROR’, error);
});
C.
Server.on (‘error’, (error) => {
console.log(‘ERROR’, error);
});
D.
Try{
server.start();
} catch(error) {
console.log(‘ERROR’, error);
Server.on (‘error’, (error) => {
console.log(‘ERROR’, error);
});
Page 3 out of 45 Pages |
Previous |