ExamGecko
Home Home / Salesforce / Certified JavaScript Developer I

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

Question list
Search
Search

List of questions

Search

Related questions











A developer is setting up a new Node.js server with a client library that is built using events and callbacks.

The library:

• Will establish a web socket connection and handle receipt of messages to the server ?

• Will be imported with require, and made available with a variable called we.

The developer also wants to add error logging if a connection fails.

Given this info, which code segment shows the correct way to set up a client with two events that listen at execution time?

A.
ws.connect (( ) => { console.log('connected to client'); }).catch((error) => { console.log('ERROR' , error); }};
A.
ws.connect (( ) => { console.log('connected to client'); }).catch((error) => { console.log('ERROR' , error); }};
Answers
B.
ws.on ('connect', ( ) => { console.log('connected to client'); ws.on('error', (error) => { console.log('ERROR' , error); });});
B.
ws.on ('connect', ( ) => { console.log('connected to client'); ws.on('error', (error) => { console.log('ERROR' , error); });});
Answers
C.
ws.on ('connect', ( ) => { console.log('connected to client'); }}; ws.on('error', (error) => { console.log('ERROR' , error); }};
C.
ws.on ('connect', ( ) => { console.log('connected to client'); }}; ws.on('error', (error) => { console.log('ERROR' , error); }};
Answers
D.
try{ ws.connect (( ) => { console.log('connected to client'); });} catch(error) { console.log('ERROR' , error); };}
D.
try{ ws.connect (( ) => { console.log('connected to client'); });} catch(error) { console.log('ERROR' , error); };}
Answers
Suggested answer: C

Refer 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]
A.
[1, 2, 3, 4, 5, 4, 4]
Answers
B.
[1, 2, 3, 4, 4, 5, 4]
B.
[1, 2, 3, 4, 4, 5, 4]
Answers
C.
[1, 2, 3, 5]
C.
[1, 2, 3, 5]
Answers
D.
[1, 2, 3, 4, 5, 4]
D.
[1, 2, 3, 4, 5, 4]
Answers
Suggested answer: B

Refer to HTML below:

<p> The current status of an Order: <span id ="status"> In Progress </span> </p>.

Which JavaScript statement changes the text 'In Progress' to 'Completed' ?

A.
document.getElementById("status").Value = 'Completed' ;
A.
document.getElementById("status").Value = 'Completed' ;
Answers
B.
document.getElementById("#status").innerHTML = 'Completed' ;
B.
document.getElementById("#status").innerHTML = 'Completed' ;
Answers
C.
document.getElementById("status").innerHTML = 'Completed' ;
C.
document.getElementById("status").innerHTML = 'Completed' ;
Answers
D.
document.getElementById(".status").innerHTML = 'Completed' ;
D.
document.getElementById(".status").innerHTML = 'Completed' ;
Answers
Suggested answer: C

A developer wants to leverage a module to print a price in pretty format, and has imported a method as shown below:

Import printPrice from '/path/PricePrettyPrint.js';

Based on the code, what must be true about the printPrice function of the PricePrettyPrint module for this import to work ?

A.
printPrice must be be a named export
A.
printPrice must be be a named export
Answers
B.
printPrice must be an all export
B.
printPrice must be an all export
Answers
C.
printPrice must be the default export
C.
printPrice must be the default export
Answers
D.
printPrice must be a multi exportc
D.
printPrice must be a multi exportc
Answers
Suggested answer: C

What are two unique features of functions defined with a fat arrow as compared to normal function definition?

Choose 2 answers

A.
The function generated its own this making it useful for separating the function's scope from its enclosing scope.
A.
The function generated its own this making it useful for separating the function's scope from its enclosing scope.
Answers
B.
The function receives an argument that is always in scope, called parentThis, which is the enclosing lexical scope.
B.
The function receives an argument that is always in scope, called parentThis, which is the enclosing lexical scope.
Answers
C.
If the function has a single expression in the function body, the expression will be evaluated and implicit returned.
C.
If the function has a single expression in the function body, the expression will be evaluated and implicit returned.
Answers
D.
The function uses the this from the enclosing scope.
D.
The function uses the this from the enclosing scope.
Answers
Suggested answer: A, B

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?

A.
Replace line 04 with console.log(input .value);
A.
Replace line 04 with console.log(input .value);
Answers
B.
Replace line 03 with const input = document.getElementByName('input');
B.
Replace line 03 with const input = document.getElementByName('input');
Answers
C.
Replace line 02 with button.addCallback("click", function() {
C.
Replace line 02 with button.addCallback("click", function() {
Answers
D.
Replace line 02 with button.addEventListener("onclick", function() {
D.
Replace line 02 with button.addEventListener("onclick", function() {
Answers
Suggested answer: A

The developer wants to test this code:

Const toNumber =(strOrNum) => strOrNum;

Which two tests are most accurate for this code?

Choose 2 answers

A.
console.assert(toNumber('2') === 2);
A.
console.assert(toNumber('2') === 2);
Answers
B.
console.assert(Number.isNaN(toNumber()));
B.
console.assert(Number.isNaN(toNumber()));
Answers
C.
console.assert(toNumber('-3') < 0);
C.
console.assert(toNumber('-3') < 0);
Answers
D.
console.assert(toNumber () === NaN);
D.
console.assert(toNumber () === NaN);
Answers
Suggested answer: A, C

A 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

A.
Sum () (20)
A.
Sum () (20)
Answers
B.
Sum (5, 5) ()
B.
Sum (5, 5) ()
Answers
C.
sum() (5, 5)
C.
sum() (5, 5)
Answers
D.
sum(5)(5)
D.
sum(5)(5)
Answers
E.
sum(10) ()
E.
sum(10) ()
Answers
Suggested answer: C, D

Refer to the code below:

function changeValue(param) {

Param =5;

} Let a =10;

Let b =5;

changeValue(b);

Const result = a+ " - "+ b;

What is the value of result when code executes?

A.
10 -10
A.
10 -10
Answers
B.
5 -5
B.
5 -5
Answers
C.
5 - 10
C.
5 - 10
Answers
D.
10 - 5
D.
10 - 5
Answers
Suggested answer: A

Refer 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);

A.
Return Number((num +10) /3 );
A.
Return Number((num +10) /3 );
Answers
B.
Return (Number (num +10 ) / 3;
B.
Return (Number (num +10 ) / 3;
Answers
C.
Return Integer(num +10) /3;
C.
Return Integer(num +10) /3;
Answers
D.
Return Number(num + 10) / 3;
D.
Return Number(num + 10) / 3;
Answers
Suggested answer: B
Total 224 questions
Go to page: of 23