JS1 Updated Flashcards
A developer initiates a server with the file server,js and adds dependencies in the source codes package,json that
are required to run the server.
Which command should the developer run to start the server locally?
A. start server,js
B. npm start server,js
C. npm start
D. node start
C
After user acceptance testing, the developer is asked to change the webpage background based on user’s
location. This change was implemented and deployed for testing.
The tester reports that the background is not changing, however it works as required when viewing on the
developer’s computer.
Which two actions will help determine accurate results?
Choose 2 answers
A . The developer should inspect their browser refresh settings.
B . The tester should disable their browser cache.
C . The developer should rework the code.
D . The tester should clear their browser cache.
A, D
A developer wants to use a module called DataPrettyPrint. This module exports one default function called
printDate ().
How can a developer import and use the printDate() function?
A. import DataPrettyPrint from ‘/path/DataPrettyPrint.js’/
DataPrettyPrint.printDate();
B. import printDate from ‘/path/DataPrettyPrint.js’/
printDate();
C. import printDate from ‘/path/DataPrettyPrint.js’/
DataPrettyPrint.printDate();
D. import DataPrettyPrint() from ‘/path/DataPrettyPrint.js’/
printDate();
B
A developer has the function, shown below, that is called when a page loads.
function onLoad(){
console.log(‘Page has Loaded’);
}
Where can the developer see the log statement after loading the page in the browser?
A . On the browser JavaScript console
B . On the terminal console running the web server
C . In the browser performance tools log
D . On the webpage console log
A
A developer at Universal Containers is creating their new landing page based on HTML, CSS, and JavaScript.
To ensure that visitors have a good experience, a script named personalizeWebsiteContent needs to be executed
when the webpage is fully loaded (HTML content and all related files), in order to do some custom initializations.
Which implementation should be used to call Fe:s:-a;::eHec5;te::.-.ter.: based on the business requirement above?
A . Add a listener to the window object to handle the DOMContentLoaded event
B . Add a handler to the personalizeWebsiteContent script to handle the load event
C . Add a listener to the window object to handle the lead event
D . Add a handler to the personalizeWebsiteContent script to handle the DOMContentLoaded event
C
Given the following code:
01 lext x = null;
02 console.log(typeof x);
What is the output of line 02?
A . ‘null’
B . ‘x
C . ‘undefined’ 0
D . ‘object’
D
A developer tries to retrieve all cookies, then sets a certain key value pair in the cookie. These statements are
used:
01 document.cookie;
02 documet.cookie = ‘key=John Smith’;
What is the behavior?
A . Cookies are read, but the key value is not set because the value is not URL encoded.
B . Cookies are not read because line 01 should be document, cookies, but the key value is set and all cookies are
wiped.
C . A Cookies are read and the key value is set, the remaining cookies are unaffected.
D . Cookies are read and the key value is set, and all cookies are wiped.
C
Given the JavaScript below:
01 function filterDOM(searchString){
02 const parsedSearchString = searchsting && searchsting.toLowerCase();
03 document.querySelectorAll(‘.account’).forEach(account => {
04 const accountName = account.innerHTML.toLowerCase();
05 account.style.display = accountName.include(parseSearchString) ? //InsertCodeHere//
06 });
07 }
Which code should replace the placeholder comment on line 06 to hide accounts that do not match the search
string?
A . ‘None’ : ‘block’
B . ‘Visible : ‘hidden’
C . ‘Hidden, visible
D . ‘Block’ : ‘none
D
Refer to the code below:
01 function execute() {
02 return new promise((resolve, reject) => reject());
03 }
04 let promise = execute();
05
06 promise
07 .then(() => console.log(‘Resolved1’))
08 .then(() => console.log(‘Resolved2’))
09 .then(() => console.log(‘Resolved3’))
10 .catch(() => console.log(‘rejected’))
11 .then(() => console.log(‘Resolved4’));
What is the result when the Promise in the execute function is rejected?
A . Resolved1 Resolved2 Resolved3 Resolved4
B . Rejected
C . Rejected Resolved
D . Rejected1 Rejected2 Rejected3 Rejected Rejected Rejected4
C
Refer to the code below:
const car = {
price:100,
getPrice:function(){
return this.price;
}
};
const customCar = Object.create(car);
customCar.price = 70;
delete customCar.price;const result = customCar.getPrice();
What is the value of result after the code executes?
A . 100
B . undefined
C . null
D . 70
A
Refer to the following code:
class Vehicle{
constructor(plate){
this.plate = plate;
}
}
class Truck extends Vehicle{
constructor(plate, weight){
//Missing code
this.weight = weight;
}
displayWeight(){
console.log(The truck ${this.plate} has a weight of ${this.weight}lb.
);
}
}let myTruck = new Truck(‘123Ab’,5000);
myTruck.displayWeight();
Which statement should be added to missing code for the code to display ‘The truck 123AB has a
weight of 5000lb.
A . super(plate)
B . super.plate = plate
C . Vehicle.plate = plate
D . this.plate = plate
A
A developer has two ways to write a function:
Option A:
function Monster(){
this.growl = ()=>{
console.log(‘Grr!’);
}
}
Option B:
function Monster(){};
Monster.prototype.growl = ()=>{
console.log(‘Grr!’);
}
After deciding on an option, the developer creates 1000 monster objects.
How many growl methods are created with Option A and Option B?
A . 1000 for Option A, 1 for Option B
B . 1 methods for both
C . 1000 for both
D . 1 for Option A, 1000 for Option B
A
Refer to the code below
let inArray = [[1,2],[3,4,5]];
which two statements results in the array [1,2,3,4,5]?
choose 2 answer
A . [ ].concat(…inArray);
B . [ ].concat.apply(inArray,[ ]);
C . [ ].concat([…inArray])
D . [ ].concat.apply([ ],inArray);
A, D
At Universal Containers, every team has its own way of copying JavaScript objects. The code snippet shows an
Implementation from one team:
01 function Person() {
02 this.firstName = ‘John’:
03 this.lastName = ‘Doe’;
04 this.name = () => {
05 console.log(‘Hello $(this.firstName) $(this.lastName)’))
07 }
08}
09 const john = new Person();
10 const dan = JSON.stringify(JSON.parse(john));
11 dan.firstName = ‘Dan’;
12 dan.name();
What is the output of the code execution?
A . Hello John Doe
B . Hello Dan
C . Hello Dan Doe
D . SyntaxError: Unexpected token in JSON
D
A developer writes the code below to calculate the factorial of a given number
function sum(number){
return number * sum(number-1);
}
sum(3);
what is the result of executing the code.
A . 0
B . 6
C . Error
D . -Infinity
C
Given the code below:
const delay = async delay =>{
return new Promise((resolve,reject)=>{
console.log(1);
setTimeout(resolve,deleay);
});
};
const callDelay = async ()=>{
console.log(2);
const yup = await delay(1000);
console.log(3);
}
console.log(4);
callDelay();
console.log(5);
What is logged to the console?
A . 4 2 1 5 3
B . 4 2 1 5 6
C. 4 5 1 2 3
D. 4 5 2 3 1
A
Refer to the code below:
let car1 = new Promise((_ ,reject)=> setTimeout(reject,2000,’Car1 crashed in’));
let car2 = new Promise(resolve => setTimeout(resolve,1500,’Car2 completed’));
let car3 = new Promise(resolve => setTimeout(resolve,3000,’Car3 completed’));
Promise.race([car1,car2,car3])
.then(value=>{
let result = ${value} the race.
;
}).catch(err=>{
console.log(‘Race is cancelled.’,err);
});
What is the value of result when promise.race execues?
A. Car1 completed the race.
B. Car2 completed the race.
C. Car3 completed the race.
D Race is cancelled.
B
Given the following code:
let x = null;
console.log(typeof x);
What is the output?
A . ‘object’
B . ‘undefined’
C . ‘null’
D . ‘x’
A
Refer to the code below:
01 document.body.addEventListner(‘click’,(event)=>{
02 if(//Answer Goes here//){
03 console.log(‘myElement clicked);
04 }
05 });
Which replacement for the conditional statement on line 02 allows a developer to correctly determine
that a specific element, myElement on the page had been clicked?
A. event.target.id ==’myElement’
B. event.target ==’myElemnt’
C. event
D. target.id == ‘myElement’
A
Refer to the HTML below:
//<div id='main'>
//<ul>
//<li>Leo</li>
//<li>Tony</li>
//<li>Tiger</li>
//</ul>
//</div>
Which JavaScript statement results in changing ‘’ The Lion.’’?
A . document.querySelectorAll(‘$main $TONY’).innerHTML = ‘’’ The Lion
B . document.querySelector(‘$main li:second-child’).innerHTML = ‘’ The Lion ‘;
C . document.querySelector(‘$main li.Tony’).innerHTML = ‘’’ The Lion ‘;
D . document.querySelector(‘$main li:nth-child(2)’),innerHTML = ‘’ The Lion. ‘;
A
Refer to the following code:
//<html lang=’en;>
//<body>
//<span onclick=’console.log(‘Span Message);”>
//<button> Send Message</button>
//</span>
//</body>
//
function displayMessage(ev){
ev.stopPropagation();
console.log(‘button message’);
}
const elem = document.getElementById(‘mybutton’);
elem.addEventListner(‘click’, displayMessage);
//</script>
//</html>
A . document.querySelectorAll(‘$main $TONY’).innerHTML = ‘’’ The Lion
B . document.querySelector(‘$main li:second-child’).innerHTML = ‘’ The Lion ‘;
C . document.querySelector(‘$main li.Tony’).innerHTML = ‘’’ The Lion ‘;
D . document.querySelector(‘$main li:nth-child(2)’),innerHTML = ‘’ The Lion. ‘;
A
Given the HTML below:
//<div>
//<div id='row-wc'>Univeral Containers</div>
//<div id='row-as'>Applied Shipping</div>
//<div id='row-bt'>Burlington Textiles</div>
//</div>
Which statement adds the priority-account css class to the Applied Shipping row?
A. document.querySelector(‘#row-as’).classList.add(‘priority-account’);
B. document.query (‘#row-as’).classList.add(‘priority-account’);
C. document.querySelector(‘#row-wc’).classList.add(‘priority-account’);
D. document.query (‘#row-bt’).classList.add(‘priority-account’);
A
Refer to the following code block:
class Animal{
constructor(name){
this.name = name;
}
makeSound(){
console.log(${this.name} is making a sound.
)
}
}
class Dog extends Animal{
constructor(name){
super(name)
this.name = name;
}
makeSound(){
console.log(${this.name} is barking.
)
}
}
let myDog = new Dog(‘Puppy’);
myDog.makeSound();
What is the console output?
A . Puppy is barking
B . Puppy is cracking
C. Puppy is making a sound
D. Undefined
A
A developer has an is Dog function that takes one argument cat. They want to schedule the function to run every
minute.
What is the correct syntax for scheduling this function?
A developer has an is Dog function that takes one argument cat. They want to schedule the function to run every
minute.
What is the correct syntax for scheduling this function?
A . setInterval(isDog, 60000,’cat’);
B . setInterval(isDog, 50000,’cat’);
C . setTimeout(isDog, 60000,’cat’);
D . setTimeout(isDog, 50000,’cat’);
A
Click me! | //