Quiz
Salesforce JavaScript Developer I
Fragen in diesem Quiz (57)
1Refer 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:- ANon-primitive values are mutable.
- BNon-primitive values are immutable.
- CPrimitive values are mutable.
- DPrimitive values are immutable.
22. What are two unique features of functions defined with a fat arrow as compared to normal function definition? Choose 2 answers
- AThe function generated its own this making it useful for separating the function’s scope from its enclosing scope.
- BIf the function has a single expression in the function body, the expression will be evaluated and implicit returned.
- CThe function receives an argument that is always in scope, called parentThis, which is the enclosing lexical scope.
- DThe function uses the this from the enclosing scope.
3Refer 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- A‘Update’ , (
recordId : ‘123abc’
( - Bcorrect
‘Update’ , ‘123abc’
{ type : ‘update’, recordId : ‘123abc’ } - C‘Update’ , {
Details : {
recordId : ‘123abc’
}
}
- A‘Update’ , (
4At Universal Containers, every team has its own way of copying JavaScript objects.
The code Snippet shows an implementation from one team:
Function Person() {
this.firstName = “John”;
this.lastName = ‘Doe’;
This.name =() => (
console.log(‘Hello $(this.firstName) $(this.firstName)’);
)}
Const john = new Person ();
Const dan = JSON.parse(JSON.stringify(john));
dan.firstName =’Dan’;
dan.name();
What is the Output of the code execution?- AHello Dan Doe
- BHello John DOe
- CTypeError: dan.name is not a function
- DTypeError: Assignment to constant variable
5Refer to the code below:
catch( arr => (
10 console.log(“Race is cancelled.”, err);
11 ));
What is the value of result when Promise.race executes?- ACar 3 completed the race.
- BCar 1 crashed in the race.
- CCar 2 completed the race.
- DRace is cancelled.
6Given the code below:
Function myFunction(){
A =5; Var b =1;
}
myFunction();
console.log(a);
console.log(b);
What is the expected output?- ABoth lines 08 and 09 are executed, and the variables are outputted.
- BLine 08 outputs the variable, but line 09 throws an error.
- CLine 08 thrones an error, therefore line 09 is never executed.
- DBoth lines 08 and 09 are executed, but values outputted are undefined.
7Refer to the following code:
function test (val) {
If (val === undefined) {
return ‘Undefined values!’ ;
}
if (val === null) {
return ‘Null value! ’;
}
return val;
}
Let x;
test(x);
What is returned by the function call on line 13?- AUndefined
- BLine 13 throws an error.
- C‘Undefined values!’
- D‘Null value!’
8CORRECT TEXT
Given the requirement to refactor the code above to JavaScript class format, which class definition is correct?
A)
B)
C)
D)- AOption A
- BOption B
- COption C
- DOption D
9Refer to the code below:
Async funct on functionUnderTest(isOK) {
If (isOK) return ‘OK’ ;
Throw new Error(‘not OK’);
)
Which assertion accuretely tests the above code?- AConsole.assert (await functionUnderTest(true), ‘ OK ’)
- BConsole.assert (await functionUnderTest(true), ‘ not OK ’)
- CConsole.assert (await functionUnderTest(true), ‘not OK’)
- DConsole.assert (await functionUnderTest(true), ‘OK’)
10Which two code snippets show working examples of a recursive function? Choose 2 answers
- ALet countingDown = function(startNumber) { If ( startNumber >0) { console.log(startNumber) ; return countingDown(startNUmber); } else { return startNumber; }};
- BFunction factorial ( numVar ) { If (numVar < 0) return; If ( numVar === 0 ) return 1; return numVar -1;
- CConst sumToTen = numVar => { If (numVar < 0) Return; return sumToTen(numVar + 1)};
- DConst factorial =numVar => { If (numVar < 0) return; If ( numVar === 0 ) return 1; return numVar * factorial ( numVar - 1 ); };
11Refer 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 “ Tony” to “Mr. T.”?- Adocument.querySelectorAll(‘$main $TONY’).innerHTML =’ Mr.’;
- Bdocument.querySelectorAll(‘$main $TONY’).innerHTML = ’ Mr.’;
- Cdocument.querySelector(‘$main li.Tony’).innerHTML = ’ Mr.’;
- Ddocument.querySelector(‘$main li:nth-child(2)’),innerHTML = ’ Mr.’;
12Universal Containers (UC) notices that its application that allows users to search for accounts makes a network request each time a key is pressed. This results in too many requests for the server to handle.
Address this problem, UC decides to implement a debounce function on string change handler.
What are three key steps to implement this debounce function? Choose 3 answers:- AIf there is an existing setTimeout and the search string change, allow the existing setTimeout to finish, and do not enqueue a new setTimeout.
- BWhen the search string changes, enqueue the request within a setTimeout.
- CEnsure that the network request has the property debounce set to true.
- DIf there is an existing setTimeout and the search string changes, cancel the existing setTimeout using the persisted timerId and replace it with a new setTimeout.
- EStore the timeId of the setTimeout last enqueued by the search string change handle.
13Refer to the code snippet below:
Let array = [1, 2, 3, 4, 4, 5, 4, 4];
For (let i =0; i < array.length; i++)
if (array[i] === 4) {
array.splice(i, 1);
}
}
What is the value of array after the code executes?- A[1, 2, 3, 4, 5, 4, 4]
- B[1, 2, 3, 4, 4, 5, 4]
- C[1, 2, 3, 5]
- D[1, 2, 3, 4, 5, 4]
14Given 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?- A2 1 4 3 5
- B2 5 1 3 4
- C1 2 4 3 5
- D1 2 5 3 4
15Given two expressions var1 and var2.
What are two valid ways to return the logical AND of the two expressions and ensure it is data type Boolean? Choose 2 answers:- ABoolean(var1 && var2)
- Bvar1 && var2
- Cvar1.toBoolean() && var2toBoolean()
- DBoolean(var1) && Boolean(var2)
16Refer to the code below:
console.log(‘’start);
Promise.resolve(‘Success’) .then(function(value){
console.log(‘Success’);
});
console.log(‘End’);
What is the output after the code executes successfully?- AEnd
- BStart Success
- CStart Success End
- DStart End Success
- ESuccess Start
17Which code statement correctly retrieves and returns an object from localStorage?
- Aconst retrieveFromLocalStorage = () =>{ return JSON.stringify(window.localStorage.getItem(storageKey)); }
- Bconst retrieveFromLocalStorage = (storageKey) =>{ return window.localStorage.getItem(storageKey); }
- Cconst retrieveFromLocalStorage = (storageKey) =>{ return JSON.parse(window.localStorage.getItem(storageKey)); }
- Dconst retrieveFromLocalStorage = (storageKey) =>{ return window.localStorage[storageKey]; }
18Refer 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?- AaPromise and bPromise run sequentially.
- BNeither aPromise or bPromise runs.
- CaPromise and bPromise run in parallel.
- DOnly aPromise runs.
19A 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?- Aconst https =require(‘https’);
- Bconst server =require(‘secure-server’);
- Cconst tls = require(‘tls’);
- Dconst http =require(‘http’);
20Refer to the following code that performs a basic mathematical operation on a provided input:
function calculate(num) {
Return (num +10) / 3;
}
How should line 02 be written to ensure that x evaluates to 6 in the line below?
Let x = calculate (8);- AReturn Number((num +10) /3 );
- BReturn (Number (num +10 ) / 3;
- CReturn Integer(num +10) /3;
- DReturn Number(num + 10) / 3;
21A developer wrote the following code:
01 let X = object.value;
02
03 try {
4 handleObjectValue(X);
5 } catch (error) {
6 handleError(error);
7 }
The developer has a getNextValue function to execute after handleObjectValue(), but does not want to execute getNextValue() if an error occurs.
How can the developer change the code to ensure this behavior?- A03 try{ 4 handleObjectValue(x); 5 } catch(error){ 6 handleError(error); 7 } then { 8 getNextValue(); 9 }
- B03 try{ 4 handleObjectValue(x); 5 } catch(error){ 6 handleError(error); 07 } finally { 8 getNextValue(); 10 }
- C03 try{ 4 handleObjectValue(x); 5 } catch(error){ 6 handleError(error); 7 } 8 getNextValue();
- D03 try { 4 handleObjectValue(x) 5 ……………………
22Which code statement below correctly persists an objects in local Storage?
- Aconst setLocalStorage = (storageKey, jsObject) => { window.localStorage.setItem(storageKey, JSO
stringify(jsObject)); } - Bconst setLocalStorage = ( jsObject) => { window.localStorage.connectObject(jsObject)); }
- Cconst setLocalStorage = ( jsObject) => { window.localStorage.setItem(jsObject); }
- Dconst setLocalStorage = (storageKey, jsObject) => { window.localStorage.persist(storageKey, jsObject); }
- Aconst setLocalStorage = (storageKey, jsObject) => { window.localStorage.setItem(storageKey, JSO
23A developer uses a parsed JSON string 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- AuserInformation(“email”)
- BuserInformation.get(“email”)
- CuserInformation.email
- DuserInformation(email)
24Given the following code:
Counter = 0;
const logCounter = () => {
console.log(counter);
);
logCounter();
setTimeout(logCOunter, 1100);
setInterval(() => {
Counter++
logCounter();
}, 1000);
What is logged by the first four log statements?- A0 0 1 2
- B0 1 2 3
- C0 1 1 2
- D0 1 2 2
25developer 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?- A2.0.0
- B1.2.3
- C1.1.4
- D1.2.0
26A developer has an ErrorHandler module that contains multiple functions.
What kind of export be leverages so that multiple functions can be used?- ANamed
- BAll
- CMulti
- DDefault
27Refer to the code below:
Let inArray =[ [ 1, 2 ] , [ 3, 4, 5 ] ];
Which two statements result in the array [1, 2, 3, 4, 5]? Choose 2 answers- A[ ]. Concat.apply ([ ], inArray);
- B[ ]. Concat (... inArray);correct
- C[ ]. concat.apply(inArray, [ ]);
- D[ ]. concat ( [ ….inArray ] );
28Refer to code below:
Let productSKU = ‘8675309’ ;
A developer has a requirement to generate SKU numbers that are always 19 characters lon,
starting with ‘sku’, and padded with zeros.
Which statement assigns the values sku0000000008675309?- AproductSKU = productSKU.padStart (19. ‘0’).padstart(‘sku’);
- BproductSKU = productSKU.padEnd (16. ‘0’).padstart(‘sku’)
- CproductSKU = productSKU.padEnd (16. ‘0’).padstart(19, ‘sku’);
- DproductSKU = productSKU.padStart (16. ‘0’).padstart(19, ‘sku’);
29A developer writers the code below to calculate the factorial of a given number. Function factorial(number) {
Return number + factorial(number -1);
}
factorial(3);
What is the result of executing line 04?- A0
- B6
- C-Infinity
- DRuntimeError
30Refer to the following code:
01 function Tiger(){
02 this.Type = ‘Cat’;
03 this.size = ‘large’;
04 }
05
06 let tony = new Tiger();
07 tony.roar = () =>{
08 console.log(‘They’re great1’);
9 };
10
11 function Lion(){
12 this.type = ‘Cat’;
13 this.size = ‘large’;
14 }
15
16 let leo = new Lion();
17 //Insert code here
18 leo.roar();- ALeo.roar = () => { console.log(‘They’re pretty good:’); };
- BObject.assign(leo,Tiger);
- CObject.assign(leo,tony);
- DLeo.prototype.roar = () => { console.log(‘They’re pretty good:’); };
31developer wants to use a module named universalContainersLib and them call functions from it.
How should a developer import every function from the module and then call the fuctions foo and bar?- Aimport * ad lib from ‘/path/universalContainersLib.js’; lib.foo(); lib.bar();
- Bimport (foo, bar) from ‘/path/universalContainersLib.js’; foo(); bar();
- Cimport all from ‘/path/universalContaineraLib.js’; universalContainersLib.foo(); universalContainersLib.bar();
- Dimport * from ‘/path/universalContaineraLib.js’; universalContainersLib.foo(); universalContainersLib.bar();
32A developer creates a generic function to log custom messages in the console.
To do this, the function below is implemented.
01 function logStatus(status){
02 console./*Answer goes here*/{‘Item status is: %s’, status};
03 }
Which three console logging methods allow the use of string substitution in line 02?- AAssert
- BLog
- CMessage
- DInfo
- EError
33A developer has code that calculates a restaurant bill, but generates incorrect answers while testing the code:
function calculateBill ( items ) {
let total = 0;
total += findSubTotal(items);
total += addTax(total);
total += addTip(total);
return total;
}
Which option allows the developer to step into each function execution within calculateBill?- AUsing the debugger command on line 05
- BUsing the debugger command on line 03
- CCalling the console.trace (total) method on line 03
- DWrapping findSubtotal in a console.log() method
34A developer is wondering whether to use, Promise.then or Promise.catch, especially when a Promise throws an error?
Which two promises are rejected?
Which 2 are correct?- APromise.reject(‘cool error here’).then(error => console.error(error));
- BPromise.reject(‘cool error here’).catch(error => console.error(error));
- CNew Promise((resolve, reject) => (throw ‘cool error here’}).catch(error => console.error(error)) ;
- DNew Promise(() => (throw ‘cool error here’}).then(null, error => console.error(error)));
35A developer removes the HTML class attribute from the checkout button, so now it is simply:
<button>Checkout</button>.
There is a test to verify the existence of the checkout button, however it looks for a button with class= “blue”. The test fails because no such button is found.
Which type of test category describes this test?- ATrue positive
- BTrue negative
- CFalse positive
- DFalse negative
36A developer creates an object where its properties should be immutable and prevent
properties from being added or modified.
Which method should be used to execute this business requirement?- AObject.const()
- BObject.eval()
- CObject.lock()
- DObject.freeze()
37Refer to the code below:
Const searchTest = ‘Yay! Salesforce is amazing!” ;
Let result1 = searchText.search(/sales/i);
Let result 21 = searchText.search(/sales/i);
console.log(result1);
console.log(result2);
After running this code, which result is displayed on the console?- Atrue > false
- B5 >undefined
- C5 > -1
- D5 > 0
38Refer to the code below:
Function changeValue(obj) {
Obj.value = obj.value/2;
}
Const objA = (value: 10);
Const objB = objA;
changeValue(objB);
Const result = objA.value;
What is the value of result after the code executes?- A10
- BNan
- C5
- DUndefined
39A 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?- AReplace line 02 with return arr.map(( result, current) => (
- BReplace line 04 with result = result +current;
- CReplace line 03 with if(arr.length == 0 ) ( return 0; )
- DReplace line 05 with return result;
40The 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:- Aconsole.assert( arr.length === 5 );
- Barr.forEach(elem => console.assert(elem === 0)) ;
- Cconsole.assert(arr[0] === 0 && arr[ arr.length] === 0);
- Dconsole.assert (arr.length >0);
41Refer to the following code:
Let obj ={
Foo: 1,
Bar: 2
}
Let output =[],
for(let something in obj{
output.push(something);
}
console.log(output);
What is the output line 11?- A[1,2]
- B[“bar”,”foo”]
- C[“foo”,”bar”]
- D[“foo:1”,”bar:2”]
42In which situation should a developer include a try .. catch block around their function call?
- AThe function has an error that should not be silenced.
- BThe function results in an out of memory issue.
- CThe function might raise a runtime error that needs to be handled.
- DThe function contains scheduled code.
43Which three statements are true about promises? Choose 3 answers
- AThe executor of a new Promise runs automatically.
- BA Promise has a .then() method.
- CA fulfilled or rejected promise will not change states .
- DA settled promise can become resolved.
- EA pending promise can become fulfilled, settled, or rejected.
44Which statement accurately describes the behaviour of the async/ await keyworks?
- AThe associated class contains some asynchronous functions.
- BThe associated function will always return a promise
- CThe associated function can only be called via asynchronous methods
- DThe associated sometimes returns a promise.
45Refer to code below:
Let first = ‘who’;
Let second = ‘what’;
Try{
Try{
Throw new error(‘Sad trombone’);
}catch (err){
First =’Why’;
}finally {
Second =’when’;
} catch (err) { Second =’Where’;
}
What are the values for first and second once the code executes?- AFirst is Who and second is When
- BFirst is why and second is where
- CFirst is who and second is where
- DFirst is why and second is when
46A 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?- ALet arr1 = arr.filter(( val) => ( return val > 15 )) .map (( num) => ( return num *2 ))
- BLet arr1 = arr.mapBy (( num) => ( return num *2 )) .filterBy (( val ) => return val > 15 )) ;
- CLet arr1 = arr.map((num) => num*2). Filter (( val) => val > 15);
- DLet arr1 = arr.map((num) => ( num *2)).filterBy((val) => ( val >15 ));
47A developer implements a function that adds a few values.
Function sum(num) {
If (num == undefined) {
Num =0;
}
Return function( num2, num3){
If (num3 === undefined) {
Num3 =0 ;
}
Return num + num2 + num3;
}
}
Which three options can the developer invoke for this function to get a return value of 10? Choose 3 answers- ASum () (20)
- BSum (5, 5) ()
- Csum() (5, 5)
- Dsum(5)(5)
- Esum(10) ()
48Cloud Kicks has a class to represent items for sale in an online store, as shown below:
Class Item{
constructor (name, price){
this.name = name;
this.price = price;
}
formattedPrice(){
return ‘s’ + String(this.price);}}
A new business requirement comes in that requests a ClothingItem class that should have all of the properties and methods of the Item class but will also have properties that are specific to clothes.
Which line of code properly declares the clothingItem class such that it inherits from Item?- AClass ClothingItem implements Item{
- BClass ClothingItem {
- CClass ClothingItem super Item {
- DClass ClothingItem extends Item {
49A developer needs to test this function:
01 const sum3 = (arr) => (
02 if (!arr.length) return 0,
03 if (arr.length === 1) return arr[0],
04 if (arr.length === 2) return arr[0] + arr[1],
05 return arr[0] + arr[1] + arr[2],
06 );
Which two assert statements are valid tests for the function? Choose 2 answers- Aconsole.assert(sum3(1, ‘2’)) == 12);
- Bconsole.assert(sum3(0)) == 0);
- Cconsole.assert(sum3(-3, 2 )) == -1);
- Dconsole.assert(sum3(‘hello’, 2, 3, 4)) === NaN);
50A 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- AOn line 02, use event.first to test if it is the first execution.
- BOn line 04, use event.stopPropagation ( ),
- COn line 04, use button.removeEventListener(‘ click” , listen);
- DOn line 06, add an option called once to button.addEventListener().
51Given the code below:
01 function GameConsole (name) {
02 this.name = name;
3 }
4
5 GameConsole.prototype.load = function(gamename) {
6 console.log( ` $(this.name) is loading a game : $(gamename) …`);
7 )
8 function Console 16 Bit (name) {
9 GameConsole.call(this, name) ;
10 }
11 Console16bit.prototype = Object.create ( GameConsole.prototype) ;
12 //insert code here
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 ’);
What should a developer insert at line 15 to output the following message using the method?
> SNEGeneziz is loading a cartridge game: Super Monic 3x Force . . .- AConsole16bit.prototype.load(gamename) = function() {
- BConsole16bit.prototype.load = function(gamename) {
- CConsole16bit = Object.create(GameConsole.prototype).load = function (gamename) {
- DConsole16bit.prototype.load(gamename) {
52developer is trying to convince management that their team will benefit from using Node.js for a backend server that they are going to create. The server will be a web server that handles API requests from a website that the team has already built using HTML, CSS, and JavaScript.
Which three benefits of Node.js can the developer use to persuade their manager? Choose 3 answers:- AI nstalls with its own package manager to install and manage third-party libraries.
- BEnsures stability with one major release every few years.
- CPerforms a static analysis on code before execution to look for runtime errors.
- DExecutes server-side JavaScript code to avoid learning a new language.
- EUser non blocking functionality for performant request handling.
53Refer to the code:
Given the code above, which three properties are set pet1? Choose 3 answers:- AName
- BcanTalk
- CType
- DOwner
- ESize
54Refer to following code block:
Let array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,];
Let output =0;
For (let num of array){
if (output >0){
Break;
}
if(num % 2 == 0){
Continue;
}
Output +=num;
What is the value of output after the code executes?- A16
- B36
- C11
- D25
55Given the following code:
document.body.addEventListener(‘ click ’, (event) => {
if (/* CODE REPLACEMENT HERE */) {
console.log(‘button clicked!’);
)
});
Which replacement for the conditional statement on line 02 allows a developer to correctly determine that a button on page is clicked?- AEvent.clicked
- Be.nodeTarget ==this
- Cevent.target.nodeName == ‘BUTTON’
- Dbutton.addEventListener(‘click’)
56A test has a dependency on database.query. During the test the dependency is replaced with an object called database 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- AIntegration
- BBlack box
- CWhite box
- DMocking
57Given the code below:
const copy = JSON.stringify([ new String(‘ false ’), new Bollean( false ), undefined ]);
What is the value of copy?- A-- [ ”false” , { } ]--
- B-- [ false, { } ]--
- C-- [ ”false” , false, undefined ]--
- D-- [ ”false” ,false, null ]--
Informationen
- Beschreibung
- test exam
- Autor
- Dani Armngd
- Sprache
- Español
- Aufrufe
- 458
- Schlagwörter
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz