JS1 Final Flashcards
Refer to the code below:
01 const exec = (item, delay) =>{
02 new Promise(resolve => setTimeout( () => resolve(item), delay)),
03 asyncfunction runParallel() {
04 Const (result1, result2, result3) = await Promise.all{
05[exec(‘x’,‘100’),exec(‘y’,500),exec(‘z’,‘100’)]
06);
07 return parallel is done: $(result1) $(result2)$(result3)
;
08 }
}
}
Which two statements correctly execute the runParallel () function?
Choose 2 answers
A. Async runParallel () .then(data);
B. runParallel ( ). done(function(data){
return data;
});
C. runParallel () .then(data);
D. runParallel () .then(function(data)
return data
Answer: B,D
A developer needs to test this function:
01constsum3=(arr)=>(
02if(!arr.length)return0,
03 if (arr.length === 1) returnarr[0],
04 if(arr.length===2)returnarr[0]+arr[1],
05 return arr[0] + arr[1] + arr[2],
06 );
Which two assert statements are valid tests for the function?
Choose 2
A. console.assert(sum3(1, ‘2’)) == 12);
B. console.assert(sum3(0)) == 0);
C. console.assert(sum3(-3, 2 )) == -1);
D. console.assert(sum3(‘hello’, 2, 3, 4)) === NaN);
Answer: A,C
Which statement phrases successfully?
A. JSON.parse ( ‘ foo ’);
B. JSON.parse ( “ foo ” );
C. JSON.parse( “ ‘ foo ’ ” );
D. JSON.parse(‘ “ foo ” ’);
Answer: D
Refer to the code below:
01 let car1 = new promise((_, reject) =>
02 setTimeout(reject, 2000, “Car 1 crashed in”));
03 let car2 = new Promise(resolve => setTimeout(resolve, 1500, “Car 2
completed”));
04 let car3 = new Promise(resolve => setTimeout (resolve, 3000, “Car 3
Completed”));
05 Promise.race([car1, car2, car3])
06 .then(value =>(
07letresult = $(value)the race.`;
08 ))
09 .catch( arr => (
10 console.log(“Race is cancelled.”, err);
11 ));
What is the value of result when Promise.race executes?
A. Car 3 completed the race.
B. Car 1 crashed in the race.
C. Car 2 completed the race.
D. Race is cancelled
Answer: C
Refer to the code below:
for(let number =2 ; number <= 5 ; number += 1 ) {
// insert code statement here
}
The developer needs to insert a code statement in the location shown.The code
statement has these requirements:
- Does require an import
- Logs an error when the boolean statement evaluates to false
- WorksinboththebrowserandNode.js
Whichmeetthe requirements?
A. assert (number % 2 === 0);
B. console.error(number % 2 === 0);
C. console.debug(number % 2 === 0);
D. console.assert(number % 2 === 0);
Answer: D
Adeveloperisworking on an ecommerce website where the delivery date is dynamically
calculated based on the current day.Thecodelinebelowisresponsibleforthis 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?
A. deliveryDate.setDate(( new Date ( )).getDate () +9);
B. deliveryDate.setDate( Date.current () + 9);
C. deliveryDate.date = new Date(+9) ;
D. deliveryDate.date = Date.current () + 9;
A
Which three statements are true about promises?
Choose 3 answers
A. The executor of a new Promise runs automatically.
B. A Promise has a .then() method.
C. A fulfilled or rejected promise will not change states.
D. A settled promise can become resolved.
E. A pending promise can become fulfilled, settled, or rejected.
Answer: B,C,E
Given the code below:
01 function GameConsole (name) {
02 this.name =name;
03 }
04
05 GameConsole.prototype.load = function(gamename) {
06 console.log( ` $(this.name) is loading a game : $(gamename)…);
07 )
08functionConsole 16Bit(name){
09GameConsole.call(this, name);
10 }
11 Console16bit.prototype = Object.create ( GameConsole.prototype) ;
12 //insert codehere
13 console.log(
$(this.name) is loading a cartridge game : $(gamename) …`);
14 }
15 const console16bit = new Console16bit(‘ SNEGeneziz ’);
16 console16bit.load(‘ Super Nonic 3x Force’);
Whatshouldadeveloperinsert atline 15tooutputthefollowingmessageusing the
method ?
> SNEGenezizisloading a cartridge game: Super Monic 3x Force . . .
A. Console16bit.prototype.load(gamename) = function() {
B. Console16bit.prototype.load = function(gamename) {
C. Console16bit = Object.create(GameConsole.prototype).load = function
(gamename) {
D. Console16bit.prototype.load(gamename) {
Answer: B
A developer has the following array of student test grades:
Let arr = [ 7, 8, 5, 8, 9 ];
TheTeacher 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?
A. Let arr1 = arr.filter(( val) => (return val > 15 )) .map (( num) => ( return num *2 ))
B. Let arr1 = arr.mapBy (( num) => (return num 2 )) .filterBy (( val ) => return val > 15 )) ;
C. Let arr1 = arr.map((num) => num2). Filter (( val) => val > 15);
D. Let arr1 = arr.map((num) => ( num *2)).filterBy((val) => ( val >15 ));
C
A test has a dependency on database.query. During the test the dependency is replaced
with an object called data base with the method, query, that returns an array.The
developer needs to verify how many times the method was called and the arguments
used each time.
Which two test approaches describe the requirement?
Choose 2 answers
A. Integration
B. Black box
C. White box
D. Mocking
Answer: C,D
Given the JavaScript below:
01 function filterDOM (searchString) {
02 const parsedSearchString = searchString && searchString.toLowerCase() ;
03 document.quesrySelectorAll(‘ .account’ ) . forEach(account => (
04const accountName = account.innerHTML.toLOwerCase();
05 account. Style.display = accountName.includes(parsedSearchString) ? /Insert
code/;
06 )};
07 }
Whichcodeshouldreplacetheplaceholder commentonline05tohideaccountsthatdo
not match the search string?
A. ‘ name ’ : ‘ block ’
B. ‘ Block ’ : ‘ none ’
C. ‘visible’:‘hidden’
D. ‘hidden’:‘visible’
B
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 the semantic versioning format, what should the new package version number
be?
A.2.0.0
B.1.2.3
C.1.1.4
D. 1.2.0
D
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().
C, D
A developer uses aparsedJSONstring to work with user information as in the block below:
01 const userInformation={
02 “ id ” : “user-01”,
03 “email” : “user01@universalcontainers.demo”,
04 “age” : 25
Which two options access the email attribute in the object?
Choose 2 answers
A. userInformation(“email”)
B. userInformation.get(“email”)
C. userInformation.email
D. userInformation(email)
Answer: A,C
Refer to the code below:
01 const server = require(‘server’);
02 /* Insert code here*/
Adeveloperimports a library that creates a webserver. The imported library uses events and callbacks to start the servers
Which code should be inserted at the line 03 to set up an event and start the web server?
A. Server.start ();
B. server.on(‘ connect ’ , ( port) =>{
console.log(‘Listening on ’ , port) ;})
C. server()
D. serve(( port) => (
E. console.log( ‘Listening on ’, port) ;
B
Adeveloperwantstoiteratethroughanarrayofobjects andcounttheobjectsandcount
the objects whose property value, name,starts with the letter N.
Const arrObj = [{“name” : “Zach”} , {“name” : “Kate”},{“name” : “Alise”},{“name” : “Bob”},{“name” :
“Natham”},{“name” : “nathaniel”}
Refertothecodesnippetbelow:
01arrObj.reduce(( acc, curr)=>{
02//missing line02
02//missing line03
04 ). 0);
Which missing lines 02 and 03 return the correct count?
A. Constsum=curr.startsWith(‘N’)?1:0;
Return acc +sum
B. Const sum = curr.name.startsWith(‘N’) ? 1: 0;
Return acc +sum
C. Constsum=curr.startsWIth(‘N’)?1:0;
Return curr+ sum
D. Const sum = curr.name.startsWIth(‘N’) ? 1: 0;
Return curr+ sum
B
A developer creates a class that represents a blog post based on the requirement that a
Post should have a body author and view count.
The Code shown Below:
Class Post {
// Insert code here
This.body =body
This.author = author;
this.viewCount = viewCount;
}
}
Which statement should be inserted in the placeholder online 02toallowfor a variable to be set
to a new instance of a Post with the three attributes correctly populated?
A. super (body, author, viewCount){
B. Function Post (body, author, viewCount){
C. constructor (body, author, viewCount){
D. constructor() {
C
Which three options show valid methods for creating a fat arrow function?
Choose 3 answers
A. x => ( console.log(‘ executed ’);)
B. [] => ( console.log(‘ executed ’);)
C. () => ( console.log(‘ executed ’);)
D. X,y,z => ( console.log(‘ executed ’);)
E. (x,y,z) => ( console.log(‘ executed ’) ;)
A,C,E
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
record Id.
Which two options could a developer insert at the placeholder inline 02 to achieve this?
Choose 2 answers
A. ‘Update’ , (
recordId : ‘123abc’
(
B. ‘Update’ , ‘123abc’
C. { type : ‘update’, recordId : ‘123abc’ }
D. ‘Update’ , {
Details : {
recordId : ‘123abc’
}
}
Answer: A,D
Refer to the code below:
Const pi = 3.1415326,
What is the data type of pi?
A. Double
B. Number
C. Decimal
D. Float
B
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 )
D. Replace line 05 with return result;
D
Given code below:
setTimeout (() => (
console.log(1);
). 0);
console.log(2);
New Promise ((resolve,reject)) = > (
setTimeout(() => (
reject(console.log(3));
). 1000);
)).catch(() => (
console.log(4);
));
console.log(5);
What is logged to the console?
A. 2 1 4 3 5
B. 2 5 1 3 4
C. 1 2 4 3 5
D. 1 2 5 3 4
B
Which statement accurately describes the behavior of the async/ await keywords?
A. The associated class contains some asynchronous functions.
B. The associated function will always return a promise
C. The associated function can only be called via asynchronous methods
D. The associated sometimes returns a promise
B
Adeveloperisdebugging awebserverthatusesNode.js Theserverhits a runtime error
every third request to an important endpoint on the web server.
The developer added a breakpoint to the start script, that is atindex.js at the root of the
server source code. The developer wants to make use of chromeDevToolstodebug.
Which command can be run toaccessDevTools and make sure the breakdown is hit ?
A. node -i index.js
B. Node –inspect-brk index.js
C. Node inspect index.js
D. Node –inspect index.js
D
-
//
- Leo //
- Tony //
- Tiger //
Click me! | //
Click me! | //