MultipleChoice
Refer to the code below:
new Promise((resolve, reject) => {
const fraction = Math.random();
if( fraction >0.5) reject('fraction > 0.5, ' + fraction);
resolve(fraction);
})
.then(() =>console.log('resolved'))
.catch((error) => console.error(error))
.finally(() => console.log(' when am I called?'));
When does Promise.finally on line 08 get called?
OptionsMultipleChoice
Refer to the code below:
Let car1 = new Promise((_ , reject) =>
setTimeout(reject, 2000, ''car 1 crashed in'' =>
Let car2 =new Promise(resolve => setTimeout(resolve, 1500, ''car 2 completed'')
Let car3 =new Promise(resolve => setTimeout(resolve, 3000, ''car 3 completed'')
Promise.race(( car1, car2, car3))
.then (value => (
Let result = '$(value) the race.';)}
.catch(arr => {
console.log(''Race is cancelled.'', err);
});
What is the value of result when Promise.race executes?
OptionsMultipleChoice
is below:
<input type=''file'' onchange=''previewFile()''>
The JavaScript portion is:
01 function previewFile(){
02 const preview = document.querySelector('img');
03 const file = document.querySelector('input[type=file]').files[0];
04 //line 4 code
05 reader.addEventListener(''load'', () => {
06 preview.src = reader.result;
07 },false);
08 //line 8 code
09 }
In lines 04 and 08, which code allows the user to select an image from their local
computer , and to display the image in the browser?
OptionsMultipleChoice
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?
OptionsMultipleChoice
Refer to the code below:
Const myFunction = arr => {
Return arr.reduce((result, current) =>{
Return result = current;
}, 10};
}
What is the output of this function when called with an empty array ?
OptionsMultipleChoice
The developer wants to test this code:
Const toNumber =(strOrNum) => strOrNum;
Which two tests are most accurate for this code?
Choose 2 answers
OptionsMultipleChoice
Refer to the code below:
Const resolveAfterMilliseconds = (ms) => Promise.resolve (
setTimeout (( => console.log(ms), ms ));
Const aPromise = await resolveAfterMilliseconds(500);
Const bPromise = await resolveAfterMilliseconds(500);
Await aPromise, wait bPromise;
What is the result of running line 05?
OptionsMultipleChoice
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.
Here is the HTML file content:
<input type ='' text'' value=''Hello'' name =''input''>
<button type =''button'' >Display </button> The developer wrote the javascript code below:
Const button = document.querySelector('button');
button.addEvenListener('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?
OptionsMultipleChoice
Given the requirement to refactor the code above to JavaScript class format, which class
definition is correct?
OptionsMultipleChoice
R74
new Promise((resolve, reject) => {
const fraction = Math.random();
if( fraction >0.5) reject("fraction > 0.5, " + fraction);
resolve(fraction);
})
.then(() =>console.log("resolved"))
.catch((error) => console.error(error))
.finally(() => console.log(" when am I called?"));
When does Promise.finally on line 08 get called?
Options