ExamGecko
Home Home / Salesforce / Certified JavaScript Developer I

Salesforce Certified JavaScript Developer I Practice Test - Questions Answers, Page 9

Question list
Search
Search

List of questions

Search

Related questions











A developer wrote a fizzbuzz function that when passed in a number, returns the following:

• 'Fizz' if the number is divisible by 3.

• 'Buzz' if the number is divisible by 5.

• 'Fizzbuzz' if the number is divisible by both 3 and 5.

• Empty string if the number is divisible by neither 3 or 5.

Which two test cases will properly test scenarios for the fizzbuzz function?

Choose 2 answers

A.
let res = fizzbuzz(5); console.assert ( res === ' ' );
A.
let res = fizzbuzz(5); console.assert ( res === ' ' );
Answers
B.
let res = fizzbuzz(15); console.assert ( res === ' fizzbuzz ' )
B.
let res = fizzbuzz(15); console.assert ( res === ' fizzbuzz ' )
Answers
C.
let res = fizzbuzz(Infinity); console.assert ( res === ' ' )
C.
let res = fizzbuzz(Infinity); console.assert ( res === ' ' )
Answers
D.
let res = fizzbuzz(3); console.assert ( res === ' buzz ' )
D.
let res = fizzbuzz(3); console.assert ( res === ' buzz ' )
Answers
Suggested answer: B, C, D

A 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?

A.
Using the debugger command on line 05.
A.
Using the debugger command on line 05.
Answers
B.
Using the debugger command on line 03
B.
Using the debugger command on line 03
Answers
C.
Calling the console.trace (total) method on line 03.
C.
Calling the console.trace (total) method on line 03.
Answers
D.
Wrapping findSubtotal in a console.log() method.
D.
Wrapping findSubtotal in a console.log() method.
Answers
Suggested answer: A

The developer has a function that prints "Hello" to an input name. To test this, thedeveloper created a function that returns "World". However the following snippet does not print " Hello World".

What can the developer do to change the code to print "Hello World" ?

A.
Change line 7 to ) () ;
A.
Change line 7 to ) () ;
Answers
B.
Change line 2 to console.log('Hello' , name() );
B.
Change line 2 to console.log('Hello' , name() );
Answers
C.
Change line 9 to sayHello(world) ();
C.
Change line 9 to sayHello(world) ();
Answers
D.
Change line 5 to function world ( ) {
D.
Change line 5 to function world ( ) {
Answers
Suggested answer: 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.
Terminal running the web server.
A.
Terminal running the web server.
Answers
B.
Browser performance toots
B.
Browser performance toots
Answers
C.
Browser javaScript console
C.
Browser javaScript console
Answers
D.
On the webpage.
D.
On the webpage.
Answers
Suggested answer: C

Refer to the code below:

let sayHello = () => {

console.log ('Hello, world!');

};

Which code executes sayHello once, two minutes from now?

A.
setTimeout(sayHello, 12000);
A.
setTimeout(sayHello, 12000);
Answers
B.
setInterval(sayHello, 12000);
B.
setInterval(sayHello, 12000);
Answers
C.
setTimeout(sayHello(), 12000);
C.
setTimeout(sayHello(), 12000);
Answers
D.
delay(sayHello, 12000);
D.
delay(sayHello, 12000);
Answers
Suggested answer: A

What is the result of the code block?

A.
The console logs only 'flag'.
A.
The console logs only 'flag'.
Answers
B.
The console logs 'flag' and another flag.
B.
The console logs 'flag' and another flag.
Answers
C.
An error is thrown.
C.
An error is thrown.
Answers
D.
The console logs 'flag' and then an error is thrown.
D.
The console logs 'flag' and then an error is thrown.
Answers
Suggested answer: D

Refer to the following code that imports a module named utils:

import (foo, bar) from '/path/Utils.js';

foo() ;

bar() ;

Which two implementations of Utils.js export foo and bar such that the code above runs without error?

Choose 2 answers

A.
// FooUtils.js and BarUtils.js existImport (foo) from '/path/FooUtils.js';Import (boo) from ' /path/NarUtils.js';
A.
// FooUtils.js and BarUtils.js existImport (foo) from '/path/FooUtils.js';Import (boo) from ' /path/NarUtils.js';
Answers
B.
const foo = () => { return 'foo' ; }const bar = () => { return 'bar' ; }export { bar, foo }
B.
const foo = () => { return 'foo' ; }const bar = () => { return 'bar' ; }export { bar, foo }
Answers
C.
Export default class {foo() { return 'foo' ; }bar() { return 'bar' ; }}
C.
Export default class {foo() { return 'foo' ; }bar() { return 'bar' ; }}
Answers
D.
const foo = () => { return 'foo';}const bar = () => {return 'bar'; }Export default foo, bar;
D.
const foo = () => { return 'foo';}const bar = () => {return 'bar'; }Export default foo, bar;
Answers
Suggested answer: B, C

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);});
A.
Server.catch ((server) => {console.log('ERROR', error);});
Answers
B.
Server.error ((server) => {console.log('ERROR', error);});
B.
Server.error ((server) => {console.log('ERROR', error);});
Answers
C.
Server.on ('error', (error) => {console.log('ERROR', error);});
C.
Server.on ('error', (error) => {console.log('ERROR', error);});
Answers
D.
Try{server.start();} catch(error) {console.log('ERROR', error);}
D.
Try{server.start();} catch(error) {console.log('ERROR', error);}
Answers
Suggested answer: C

Refer to the following code:

function test (val) {

If (val === undefined) {

return 'Undefined values!' ;

}i

f (val === null) {

return 'Null value! ';

}

return val;

}

Let x;

test(x);

What is returned by the function call on line 13?

A.
Undefined
A.
Undefined
Answers
B.
Line 13 throws an error.
B.
Line 13 throws an error.
Answers
C.
'Undefined values!'
C.
'Undefined values!'
Answers
D.
'Null value!'
D.
'Null value!'
Answers
Suggested answer: C

Which code statement below correctly persists an objects in local Storage ?

A.
const setLocalStorage = (storageKey, jsObject) => {window.localStorage.setItem(storageKey, JSON.stringify(jsObject));}
A.
const setLocalStorage = (storageKey, jsObject) => {window.localStorage.setItem(storageKey, JSON.stringify(jsObject));}
Answers
B.
const setLocalStorage = ( jsObject) => {window.localStorage.connectObject(jsObject));}
B.
const setLocalStorage = ( jsObject) => {window.localStorage.connectObject(jsObject));}
Answers
C.
const setLocalStorage = ( jsObject) => {window.localStorage.setItem(jsObject);}
C.
const setLocalStorage = ( jsObject) => {window.localStorage.setItem(jsObject);}
Answers
D.
const setLocalStorage = (storageKey, jsObject) => {window.localStorage.persist(storageKey, jsObject);}
D.
const setLocalStorage = (storageKey, jsObject) => {window.localStorage.persist(storageKey, jsObject);}
Answers
Suggested answer: A
Total 224 questions
Go to page: of 23