Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6K views

Salesforce JavaScript Developer 1 - Practice Tests + Explns - 1

The document is a summary of answers and explanations for questions on a Salesforce JavaScript Developer practice exam. The summary includes 3 correct answers to sample multiple choice questions: 1) Three expressions that would return true for checking if a substring is part of a string. 2) Code that allows a user to select an image and display it in the browser. 3) Two console logs that would output NaN. It then provides explanations for each answer referencing JavaScript concepts like strings, FileReader API, and NaN values.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6K views

Salesforce JavaScript Developer 1 - Practice Tests + Explns - 1

The document is a summary of answers and explanations for questions on a Salesforce JavaScript Developer practice exam. The summary includes 3 correct answers to sample multiple choice questions: 1) Three expressions that would return true for checking if a substring is part of a string. 2) Code that allows a user to select an image and display it in the browser. 3) Two console logs that would output NaN. It then provides explanations for each answer referencing JavaScript concepts like strings, FileReader API, and NaN values.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 137

6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Salesforce JavaScript Developer I Practice Exam 1 -


Resultados

Voltar para revisão

Tentativa 6

Todas as perguntas

Pergunta 1: Correto
Refer to the following code:
let sampleText = 'The quick brown fox jumps';
A developer needs to determine if a certain substring is part of a string.
Which three expressions return true for the given substring?
Choose 3 answers.

sampleText.substring ('fox');

sampleText.includes ('Fox', 3);

sampleText.includes ('fox'); (Correto)

sampleText.indexOf ('quick') ! == -1; (Correto)

sampleText.includes ('quick', 4); (Correto)

Explicação
This question is related to “How to Check is a String contains a Substring in
JavaScript”.
Checking if a string contains a substring is one of the most common tasks in any
programming language. JavaScript offers different ways to perform this operation.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 1/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

1. Using includes () method:

• The search_string parameter is the string you are searching for.


• The optional_position parameter is an optional number for the starting search
position in the str. If the position parameter is omitted then the default is zero.
• If the search_string is found, then it will return TRUE, if the search_string is
not found, then it will return FALSE.
• Please Note: includes () method is case sensitive. FOX is not the same as
a fox.
• Please Note: if we use the optional_parameter as 1, then searching will start
at position 1. In JavaScript, strings use zero-based indexing which means that the
first letter is at index 0.

2. Using indexOf() method


Pre-ES6, the common way to check if a string contains a substring was to use
indexOf, which is a string method that returns -1 if the string does not contain the
substring. If the substring is found, it returns the index of the character that starts
the string.

If an index is –1 means the search string is not present in the String.

With this explanation,


the correct answers are:
sampleText.includes(‘fox’) is correct because it will return true as the search
string fox is part is string sampleText and the syntax used is correct.
sampleText.includes(‘quick’, 4) is correct because as per explanation, it will start
searching the ‘quick’ from index 4 and as per 0 based indexing, the ‘quick’ will start
from index 4 and it will return true.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 2/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

sampleText.indexOf(‘quick’) !== -1 is correct because the search string ‘quick’ is


part of sampleText therefore the index will not be equal to –1. Therefore, it returns
true.

The following answers are incorrect:


sampleText.includes ('Fox', 3); is NOT correct because includes () method is
case sensitive. FOX is not the same as fox.
sampleText.substring(‘fox’) is NOT correct because its invalid.

Screenshot – For Reference:

Visit the JavaScript Developer 1 Trailmix on


https://trailhead.salesforce.com/en/users/strailhead/trailmixes/prepare-for-your-
salesforce-javascript-developer-i-credential

Pergunta 2: Correto
A developer wants to create a simple image upload in the browser using the File
API. The HTML is below:

The JavaScript portion is:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 3/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

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?

04 const reader = new FileReader ( );


(Correto)
08 if (file) reader.readAsDataURL (file);

04 const reader = new File ( );


08 if (file) reader.readAsDataURL (file);

04 const reader = new FileReader ( );


08 if (file) URL.createObjectURL (file);

04 const reader = new File ( );


08 if (file) URL.createObjectURL (file);

Explicação
This question is related to the FileReader in JavaScript. FileReader is an object with
the sole purpose of reading data from Blob (and hence File too) objects. It
delivers the data using events, as reading from disk may take time.

FileReader Syntax and Methods:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 4/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Please find the below screenshot with the code snippet given in the question:

With this explanation and code snippet, the correct answer is:
04 const reader = new FileReader ( );
08 if (file) reader.readAsDataURL (file);

Pergunta 3: Correto
Which two console logs output NaN?
Choose 2 answers.

console.log(10 / 0);

console.log(10 / Number('5'));

console.log(10 / 'five'); (Correto)

console.log(parseInt(‘two’)); (Correto)

Explicação
JavaScript has the number type that allows you to represent numbers including
integer and floating-point numbers. And JavaScript number has a special value
called NaN, which stands for Not-a-Number.
NaN is a property of the global object. In other words, it is a variable in the global
scope.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 5/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

There are five different types of operations that return NaN:


• Number cannot be parsed (e.g. parseInt("blabla") or Number(undefined))
• Math operation where the result is not a real number (e.g. Math.sqrt(-1))
• Operand of an argument is NaN (e.g. 7 ** NaN)
• Indeterminate form (e.g. 0 * Infinity, or undefined + undefined)
• Any operation that involves a string and is not an addition operation (e.g. "foo"
/ 3)

Please find the below screenshot which represents the code snippet given in the
question and its output.

With this explanation, the correct answers are


“Console.log(10 / ‘five’);”
and
“Console.log(parseInt(‘two’));” because both will result in NaN.

Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/NaN

Pergunta 4: Correto
Which statement accurately describes an aspect of promises?

.then() manipulates and returns the original promise.

Arguments for the callback function passed to .then() are


(Correto)
optional.
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 6/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

.then() cannot be added after a catch.

In a .then() function, returning results is not necessary since callbacks


will catch the result of a previous promise.

Explicação
This question is related to the concept of Promise in JavaScript.

Let’s understand the basics of JavaScript promise. Promises are used to handle
asynchronous operations in JavaScript. They are easy to manage when dealing
with multiple asynchronous operations where callbacks can create callback hell
leading to unmanageable code.
Creating a Promise: The Promise object is created using the new keyword and
contains the promise; this is an executor function which has a resolve and a
reject callback. As the names imply, each of these callbacks returns a value with
the reject callback returning an error object.

Screenshot – Basic example of promise

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 7/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation and example in the screenshot, the correct answer is:
“Arguments for the callback function passed to .then() are optional.”

Pergunta 5: Correto
Given 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.

var1.toBoolean() && var2.toBoolean()

Boolean(var1) && Boolean(var2) (Correto)

Boolean(var1 && var2) (Correto)

var1 && var2

Explicação
Let’s understand the basics of Boolean values and Logical AND operator.
Boolean values: A Boolean value represents true or false, on or off, yes or no.
There are only two possible values of this type. Any JavaScript value can be
converted to a Boolean value.
1. The following values convert to Boolean (false):
• Undefined
• Null
• 0
• -0
• Nan
• “ “ // the empty string
2. All other values, including all objects (and arrays) convert to, and work like, true.

Please find the below screenshot with Sample Code and Output:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 8/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Logical AND Operator: Although they are called “logical”, they can be applied to
values of any type, not only Boolean.
Their result can also be of any type. The AND && operator does the following:
• Evaluate operands from left to right.
• For each operand, converts it to a boolean. If the result is false, stops and
returns the original value of that operand.
• If all operands have been evaluated (i.e. all were truthy), returns the last
operand.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 9/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Now, coming back to the question,


it says to ensure that the data type of return value should be Boolean. From the
above screenshot, it’s clear that if both
the operands are truthy then it returns the last operand.
Therefore option “var1 && var2” is NOT correct.
Also option “var1.toBoolean() && var2.toBoolean()” is NOT correct because we
do not have any function named
toBoolean(). If we use it, we get error message: TypeError: var1.toBoolean is not
a function.
Thus the correct answers are:
“Boolean(var1 && var2)" and “Boolean(var1) && Boolean(var2)”

Please find the below screenshot for more clarification:

Visit the JavaScript Developer 1 Trailmix on


https://trailhead.salesforce.com/en/users/strailhead/trailmixes/prepare-for-your-
salesforce-javascript-developer-i-credential

Pergunta 6: Correto
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 10/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Refer to the code below;

What is the output after the code executes?

ReferenceError: eyeColor is not defined

ReferenceError: assignment to undeclared variable "Person"

Developer

undefined (Correto)

Explicação
This question is related to the concept of the Constructor Function in JavaScript.
Let’s understand some basic points:
Constructor functions technically are regular functions. There are two conventions
though:
• They are named with the capital letter first.
• They should be executed only with "new" operator.

Screenshot – An example of Constructor Function

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 11/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

When a function is executed with new, it does the following steps:


• A new empty object is created and assigned to this.
• The function body executes. Usually, it modifies this, adds new properties to
it.
• The value of this is returned.

Now, coming to the question and sample code given,


we can see that:
• There is a constructor function named as Person
• In LINE-08, a new instance of Person is created using a new keyword.
• In LINE-06, there is a code adding a property named job

Please Note: Instances created by a constructor function (Person) inherit a


reference to the Person.prototype object so,
• if we add a property to Person.prototype, it will show up on instances.
• If you add a property to the Person itself, it will not show up on instances.

With this explanation,


the correct answer is “Undefined” because if we add a property to the Person
itself, it will not show up on instances.

Let’s see the sample code output given in this question:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 12/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

References:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new
https://javascript.info/prototype-inheritance

Visit the JavaScript Developer 1 Trailmix on


https://trailhead.salesforce.com/en/users/strailhead/trailmixes/prepare-for-your-
salesforce-javascript-developer-i-credential

Pergunta 7: Correto
Northern Trail Outfitters (NTO) recently launched its new landing page to host a
crowd-funding campaign. The page uses an external library to display some third-
party ads. Once the page is fully loaded, it creates more than 50 new HTML items
placed randomly inside the DOM, like the one in the code below:

All the elements include the same ad-library-item class. They are hidden by default,
and they are randomly displayed while the user navigates through the page.
Tired of all the ads, what can the developer do to temporarily and quickly remove
them?

Use the DOM inspector to prevent the load event to be fired.

Use the browser console to execute a script that removes all (Correto)
the elements containing the class ad-library-item.
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 13/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Use the browser console to execute a script that prevents the load
event to be fired.

Use the DOM inspector to remove all the elements containing the class
ad-library-item.

Explicação
This question is related to removing element with some class name in
JavaScript. This can be done using remove() method. This method removes the
specified div element and all its child nodes.

With this explanation, the correct answer is:


“Use the browser console to execute a script that removes all the elements
containing the class ad-library-item”

Pergunta 8: Correto
Refer to the code below:
Let textValue = ’1984’;
Which code assignment shows a correct way to convert this string to an integer?

Let numberValue = (Number)textValue;

Let numberValue = Number(textValue); (Correto)

Let numberValue = textValue.toInteger();

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 14/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Let numberValue = Integer(textValue);

Explicação
JavaScript provides various ways to convert a string value into a number. The
best option is to use the Number object, in a non-constructor context (without the
new keyword):

The correct syntax to use Number object is:


const variable_name = Number(‘1234’);
• This takes care of the decimals as well.
• Number is a wrapper object that can perform many operations. If we use the
constructor (new Number ("1234")) it returns us a Number object instead of a
number value, so pay attention.
Please find the below sample code for more clarification:

With this explanation,


the correct answer is: “Let numberValue = Number(textValue);” because this is
the correct syntax to use Number object to convert a string value into a number.

The following options are incorrect:


Option “Let numberValue = Integer(textValue);” is NOT correct because this is
invalid. We get ReferenceError: Integer is not defined while using this option.
Option “Let numberValue = textValue.toInteger();” is NOT correct because this is
invalid. We get TypeError: textValue.toInteger() is not a function.
Option “Let numberValue = (Number)textValue;” is NOT correct because this is
not the correct syntax to use the Number Object.
The correct syntax is: let numberValue = Number(textValue);

PRO TIP:
Other Solutions to convert a string value into a number is to use:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 15/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

• parseInt()
• parseFloat()

Pergunta 9: Correto
Refer to the code below:

What is displayed when myFunction (true) is called?

2222

2211

2 2 undefined undefined

2212 (Correto)

Explicação
This question is related to the concept of var and let keywords.
The old way to declare the variables in JavaScript is using “var” but with ES6, we
can also declare the variables using “let” and “const”. Let’s understand the use case
of “var” and “let” and the difference between them.

About “var”
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 16/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

1. Scope of “var”: Scope essentially means where these variables are available
for use. var declarations are globally scoped or function/locally scoped.
• The scope is global when a var variable is declared outside a function.
• The scope is local when it is declared within a function.
2. Var variables can be re-declared and updated
This means within the same scope, we can redeclare the var variables and update
it.

About “let”
1. Scope of “let: It is block scoped. A block is a chunk of code bounded by {}
means anything within curly braces is a block. So, a variable declared in a block
with let is only available for use within that block.
2. “let” can be updated but not re-declared
Just like var, a variable declared with let can be updated within its scope. Unlike var,
a let variable cannot be re-declared within its scope.

With this explanation,


file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 17/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

let’s look at the sample code given in the question.


• As we know that let is block scoped so let x = 1 in LINE-02 and let x = 2 in
LINE-06 has different scope so LINE-08 will print 2 but LINE-12 will print 1 because
at LINE-12 will refer the scope of x from LINE-02.
• As we know that var is local scoped if declared inside function and can be re-
declared and updated so, here, var y is declared and defined at LINE-03 and
updated at LINE-07. So inside a function, it will display the updated value.
Therefore LINE-09 and LINE-13 will display 2.

So, the correct answer is:


“2 2 1 2”

Screenshot – Sample Code given in the question with output

Visit the JavaScript Developer 1 Trailmix on


https://trailhead.salesforce.com/en/users/strailhead/trailmixes/prepare-for-your-
salesforce-javascript-developer-i-credential

Pergunta 10: Correto


Refer to the code below:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 18/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Considering the implications of line 10 along with prototype inheritance, what is the
value of the result after the code executes?

null

100 (Correto)

70

undefined

Explicação
This question is related to the concept of Objects and Inheritance in JavaScript.

Let’s understand a few basic concepts.


JavaScript is designed on a simple object-based paradigm. An object is a
collection of properties, and a property is an association between a name (or key)
and a value. A property's value can be a function, in which case the property is
known as a method.
There are different ways to create objects but one of the ways is using the
Object.create method. Objects can also be created using the Object.create()
method. This method can be very useful, because it allows you to choose the
prototype object for the object you want to create, without having to define a
constructor function.

Inheritance & Prototype Chain


file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 19/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

In programming, we often want to take something and extend it. For instance, we
have a user object with its properties and methods and want to make admin and
guest as slightly modified variants of it.
In JavaScript, objects have a special hidden property [[Prototype]] (as named in the
specification), that is either null or references another object.
That object is called “a prototype”:

Please Note:
When we read a property from an object, and it’s missing, JavaScript automatically
takes it from the prototype. In programming, this is called “prototypal inheritance”.
Now, coming back to the question and code, we see that:
• An object “customCar” is created using “car” object.
• Then, customCar.price property is assigned with a value of 70.
• Then, customCar.price property is deleted.

Since, the customCar.price property is deleted, if customCar.price is accessed, it


will automatically from the prototype. That means, it will automatically take the value
of price from car object that is 100.

Let’s run the code given in the question:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 20/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation,


the correct answer is “100”

References:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Guide/Working_with_Objects
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain

Visit the JavaScript Developer 1 Trailmix on


https://trailhead.salesforce.com/en/users/strailhead/trailmixes/prepare-for-your-
salesforce-javascript-developer-i-credential

Pergunta 11: Correto


Refer to the code below:

What is the value of result when the code executes?

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 21/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

5-5

10-5

10-10 (Correto)

5-10

Explicação
This question is related to the concept of global variables and local variables in
JavaScript.

Variables: It holds the data or information which can be changed anytime.


JavaScript use reserved keyword var to declare variables. In JavaScript, there are
two types of variables and also it tells you where in your program you are allowed to
use the variables and functions that you’ve defined.
• Local Variable: When you use JavaScript, local variables are variables that
are defined within functions. They have local scope, which means that they can only
be used within the functions that define them.
Since local variables are defined inside the function so variables with the same
name can be used in different functions.
• Global Variable: In contrast, global variables are variables that are defined
outside of functions. These variables have global scope, so they can be used by
any function without passing them to the function as parameters.

Now, coming back to the question, we see


• param is the local variable
• b = 10 (because a is 10)
• When we call changeValue(b) i.e. changeValue(10) will not have any effect
on the value of b.
• So, a = 10 and b = 10 so, the output will be 10-10

Screenshot – Code Snippet given in the Question

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 22/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation,


the correct answer is “10-10”

Pergunta 12: Correto


Teams at Cloud Kicks (CK) work on multiple JavaScript projects at the same time.
CK is thinking about reusability and how each team can benefit from the work of
others.
Going open-source or public is not an option at this time.
Which option is available to CK with npm?

Private packages can be scoped, and scopes can be


(Correto)
associated to private registries.

Private registries are not supported by npm, but packages can be


installed via URL.

Private registries are not supported by npm, but packages can be


installed via git.

Private packages are not supported, but they can use another package
manager like yarn.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 23/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Explicação
This question is related to private packages in npm.
With npm private packages, you can use the npm registry to host code that is only
visible to you and your chosen collaborators, allowing you to manage and use
private code alongside public code in your projects.

Private packages always have a scope, and scoped packages are private by
default.
• User-scoped private packages can only be accessed by you and
collaborators to whom you have granted read or read/write access.
• Organization-scoped private packages can only be accessed by teams
that have been granted read or read/write access.

To use private packages, you must:


• be using npm version 2.7.0 or greater.
• Have a paid user or organization account.

With this explanation, the correct answer is:


“Private packages can be scoped, and scopes can be associated to private
registries.”

Pergunta 13: Correto


Refer to the code below:
01 let car1 = new Promise((_ , reject) =>
02 setTimeout(reject, 2000, “car 1 crashed in”));
03 let car2 =new Promise(resolve => setTimeout(resolve, 1500, “car 2
completed”));
04 let car3 =new Promise(resolve => setTimeout(resolve, 3000, “car 3
completed”));
05
06 Promise.race([car1, car2, car3])
07 .then (value => (
08 let result = ‘$(value) the race.’;
09 )}
10 .catch(arr => {
11 console.log(“Race is cancelled.”, err);
12 });

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 24/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

What is the value of result when Promise.race executes?

Car 3 completed the race.

Car 2 completed the race. (Correto)

Car 1 crashed in the race.

Race is cancelled.

Explicação
This question is related to the concept of Promise and Promise.race() static
method in JavaScript. With Promises, we can defer the execution of a code block
until an asynchronous request is completed. This way, other operations can keep
running without interruption.

Screenshot – An illustration of the life of promise

Promises have three states:


• Pending: This is the initial state of the Promise before an operation begins
• Fulfilled: This means the specified operation was completed
• Rejected: The operation did not complete; an error value is usually thrown

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 25/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Creating a Promise: The Promise object is created using the new keyword and
contains the promise; this is an executor function which has a resolve and a
reject callback. As the names imply, each of these callbacks returns a value with
the reject callback returning an error object.

Screenshot: Using a Promise

Promise.race() static method:


The Promise.race() static method accepts a list of promises and returns a
promise that fulfills or rejects as soon as there is one promise that fulfills or rejects,
with the value or reason from that promise.
Here is the syntax of the Promise.race() method:

Where, iterable is an iterable object that contains a list of promises.


Screenshot – JavaScript Promise.race() Demo

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 26/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Now, coming back to the question,


there are 3 promises named
• car1 (2000 millisecond)
• car2 (1500 millisecond)
• car3 (3000 millisecond)
The promise.race() static method is called with all the 3 promises; car1, car2, and
car3. Now, you can easily answer it. Since the time for promise car2 is least among
all so, it will execute first.

Therefore the correct answer is


“car 2 completed the race” because car2 is least among all so, it will execute first
and car2 resolves with a string “car 2 completed”.

Pergunta 14: Correto


Refer to the code below:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 27/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

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.

'update', {
recordId : '123abc' (Correto)
}

{type : 'update', recordId : '123abc' }

'update', '123abc'

'update', {
detail : {
recordId : '123abc' (Correto)
}
}

Explicação
This question is related to the concept of custom events in JavaScript.

Events are used in almost every web application, such as the onclick event being
used to execute some code when the user clicks on something. There are already
numerous built-in events available to be used, but what if we want our own custom
event? Let us suppose we are creating a chat application, and we want to execute
some code when the end-user sends some message. There is no built-in event to
detect that. Here we need a custom event that can handle such custom scenarios.

In JavaScript, a custom event can be created in 2 ways:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 28/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

• Using the Event constructor


• Using the CustomEvent constructor

The drawback of using Event Constructor is that you can’t send data across to
the listener. However, in most applications, we would want to be able to send data
across from where the event is being dispatched to the listener. To do this, we can
use the CustomEvent.
Creating a custom event using CustomEvent Constructor:
Creating custom events using the CustomEvent constructor has an advantage as it
can send custom data. The below steps are followed in order to create a new
CustomEvent.
Using CustomEvent, any data that needs to be passed to the listener can be
passed in the detailed property, which is created when initializing the event.

Syntax: CustomEvent

Screenshot – Example code snippet given in this question

In this question, two correct answers are asked but I found that the below answer
perfect one.
I am debugging it more. I will update you in a few days.
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 29/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

'update', {
detail : {
recordId : '123ab'
}
}

Pergunta 15: Correto


Refer to the code below:

The developer needs to insert a code statement in the location shown. The code
statement has these requirements:
1. Does not require an import
2. Logs an error when the Boolean statement evaluates to false
3. Works in both the browser and Node.js
Which statement meets these requirements?

console.assert (number % 2 === 0); (Correto)

console.error(number % 2 === 0);

console.debug(number % 2 === 0);

assert(number % 2 === 0);

Explicação
This question is related to different console methods used to log an error.

Let’s understand about few methods:


1. console.assert()
The console.assert() method is an inbuilt application programming interface of the
console module which is used to assert value passed to it as a parameter, i.e. it

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 30/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

checks whether the value is true or not and print an error message if provided and
failed to assert the value.
Syntax:
console.assert(value, message);

2. console.error()
The console.error() function from console class of Node.js is used to display error
messages on the console. It prints to stderr with a newline. It works with both
browser and node.js.

3. console.debug()
The console.debug() method is an inbuilt application programming interface of the
console module which is used to print messages to stdout in a newline. Similar to
console.log() method.

Now, coming back to the question,


it says that “Logs an error when the Boolean statement evaluates to false” so, only
console.assert() is able to evaluate the condition and log error when FALSE.

Therefore the correct answer is


“console.assert (number % 2 === 0);”

Please find the below code examples for Node.js and Browser
Example – Node.js

Example – Browser

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 31/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Pergunta 16: Correto


Refer to the code below:
let productSkU = '8675309";
A developer has a requirement to generate SKU numbers that are always 19
characters long, starting with ‘sku’, and padded with zeros.
Which statement assigns the value sku0000000008675309?

productSKU = productSKU.padStart(16, '0') .padStart(19,


(Correto)
'sku');

productSKU = productSKU.padEnd(16, '0') .padStart('sku');

productSKU = productSKU.padStart(19, '0') .padStart('sku');

productSKU = productSKU.padEnd(16, '0') .padStart(19, 'sku');

Explicação
First of all, let’s understand the concept of padStart() and padEnd() methods in
JavaScript.
1. padStart()

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 32/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

The padStart() method pads the current string with another string so that the
resulting string reaches the given length. The padding is applied from the start (left)
of the current string.

In Short, Keep prepending a string to another string until the target length is
met.

The padStart() method takes 2 parameters:


• targetLength: The length of the final string after current string has been
padded. For targetLength < str.length, the string is returned unmodified.
• padString (OPTIONAL): It is the string that is to be padded with the original
string

Return Value: It returns the final string that is padded with the given string to the
given length.
Note: If padString is too long, it will be truncated from the end to meet targetLength.
Screenshot – Sample Code – padStart()

2. padEnd()

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 33/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

The padStart() method pads the current string with another string so that the
resulting string reaches the given length. The padding is applied from the End
(right) of the current string.

In Short, Keep appending a string to another string until the target length is met.

The padEnd() method takes 2 parameters:


• targetLength: The length of the final string after current string has been
padded. For targetLength < str.length, the string is returned unmodified.
• padString (OPTIONAL): The string to pad current string with. Its default value
is " ".

Note: If padString is too long, it will be truncated to meet targetLength


Return Value: Returns a String of the specified targetLength with padString applied
to the end of the current string.

Screenshot – Sample Code – padEnd()

Now, coming back to the question, few important points to note:


file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 34/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

• Given productSKU = ‘8675309’


• Resulting number should be 19 character long
• The string to pad is 0 (zero)
• Resulting string should start with ‘sku’
• Resulting example: sku000000000867530

From these requirements,


• We know that the resulting string should be 19 character long and starting
with ‘sku’ (length = 3) So, the productSKU without ‘sku’ should be 16 character.
Therefore we can use productSKU.padStart(16,'0') i.e. 000000000867530
• After the productSKU is padded zeros (0) at the begin, now the resulting
number should be 19 character long with ‘sku’ as beginning.
Therefore we can use: productSKU.padStart(16,'0').padStart(19,'SKU') i.e.
sku000000000867530

Therefore, the correct answer is:


productSKU = productSKU.padStart(16, '0') .padStart(19, 'sku');

Please see below code snippet for more detail:

Pergunta 17: Correto


Refer to the code below:
01 console.log('Start');
02 Promise.resolve('Success').then(function(value) {
03 console.log('Success');

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 35/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

04 });
O5 console.log('End');
What is the output after the code executes successfully?

End
Start
Success

Success
Start
End

Start
End (Correto)
Success

Start
Success
End

Explicação
Let’s understand the basics of JavaScript promise.
Promises are used to handle asynchronous operations in JavaScript. They are
easy to manage when dealing with multiple asynchronous operations where
callbacks can create callback hell leading to unmanageable code.
Creating a Promise: The Promise object is created using the new keyword and
contains the promise; this is an executor function which has a resolve and a
reject callback. As the names imply, each of these callbacks returns a value with
the reject callback returning an error object.

In simple words, we can use Promise to perform Asynchronous operation without


disturbing the synchronous operation.
Now, coming back to the question, we see there is a code snippet given which has
synchronous JavaScript code and in between, there is some Asynchronous code

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 36/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

that uses promise. When there will be any Asynchronous code, it will be executed
as a separate thread and the Synchronous code execution will not be disturbed.

Please find the code snippet and its output:

With this explanation and example, the correct answer is:


Start
End
Success
Because “Start” is the first statement, then the promise will execute in a separate
thread until its completed and Synchronous code will continue to execute so “End”
will print then the Asynchronous code will resolve and print “Success”

Pergunta 18: Correto


Given the following code:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 37/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

What is logged by the first four log statements?

0112 (Correto)

0122

0123

0012

Explicação
This question is related to the concept of Arrow Functions, SetTimeout() and
SetInterval() in JavaScript.

Let’s understand each of them:


1. Arrow Functions
In JavaScript, there’s another very simple and concise syntax for creating functions,
that’s often better than Function Expressions. It’s called “arrow functions”.
Screenshot – Syntax of Arrow Function

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 38/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Screenshot – Example of Arrow Function

2. Scheduling: setTimeout and setInterval


We may decide to execute a function not right now, but at a certain time later. That’s
called “Scheduling a call”.
There are two methods for it:
• setTimeout allows us to run a function once after the interval of time.
• setInterval allows us to run a function repeatedly, starting after the interval of
time, then repeating continuously at that interval.

Now, coming back to the question,


please note the below points:
1. We see that there is an Arrow Function named logCounter at LINE-02
which prints the latest value of a variable counter.
2. We see that the Arrow Function logCounter is called at LINE-05. This will
print 0 because, at this time, the value of the counter variable is 0.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 39/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

3. At LINE-06, we see the Arrow Function logCounter is called after 1100ms,


but before that 1100ms completes, the code executed LINE-08 and incremented
counter value to 1 and called logCounter() function at LINE-09.
This will print 1 and then the logCounter() of LINE-06 will execute which will print
1.
4. Then after each 1000ms, it will increment the counter and print.
Screenshot – Sample Code Given in Question & Output

With this explanation,


the correct answer is: “0 1 1 2”

Reference:
https://javascript.info/settimeout-setinterval
Visit the JavaScript Developer 1 Trailmix on
https://trailhead.salesforce.com/en/users/strailhead/trailmixes/prepare-for-your-
salesforce-javascript-developer-i-credential

Pergunta 19: Correto


A developer has two ways to write a function:
Option A:

Option B:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 40/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

After deciding on an option, the developer creates 1000 monster objects.


How many growl methods are created with Option A and Option B?

1000 growl methods are created regardless of which option is used.

1 growl method is created regardless of which option is used.

1 growl method is created for Option A. 1000 growl methods are


created for Option B.

1000 growl methods are created for Option A. 1 growl


(Correto)
method is created for Option B.

Explicação
This question is related to JavaScript prototype methods vs. Object methods. In
JavaScript, when you define an object, you can attach its functions in two different
ways.
1. Inside object's constructor function, using this.func = function(){...}
2. Using prototype. i.e. Obj.prototype.func = function() {...}.

Please Note: Prototype is fast and memory efficient.


When you attach methods to object instances, then each instance will have its own
copy of the method. This involves the system processing time and the memory.
But, when you attach the method to object's prototype, then only one version of
the method exists. This doesn't need as much processing time and memory when
compared to the above approach.
In short: Use prototype - which is effective for most cases. If your objective is to
share common functionality between your object instances, then prototype is the
way to go.

With this explanation and code snippet given in the question, we can conclude
that if we use

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 41/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Object.prototype.function then only one version of the method exists, which


means, 1 growl method is created
for option B.

Therefore the correct answer is:


“1000 growl methods are created for Option A. 1 growl method is created for
Option B”

For more detailed understanding and hands-on.

Pergunta 20: Correto


Refer to the code below:
01 new Promise((resolve, reject) => {
02 const fraction = Math.random();
03 if( fraction >0.5) reject(‘fraction > 0.5, ‘ + fraction);
04 resolve(fraction);
05 })
06 .then(() =>console.log(‘resolved’))
07 .catch((error) => console.error(error))
08 .finally(() => console.log( ‘when am I called?’));

When does Promise.finally on line 08 get called?

When resolved or rejected. (Correto)

When resolved and settled.

When rejected.

When resolved.

Explicação
This question is related to the concept of Promise and Promise.race() static
method in JavaScript. With Promises, we can defer the execution of a code block

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 42/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

until an asynchronous request is completed. This way, other operations can keep
running without interruption.

Screenshot – An illustration of the life of promise

Promises have three states:


• Pending: This is the initial state of the Promise before an operation begins
• Fulfilled: This means the specified operation was completed
• Rejected: The operation did not complete; an error value is usually thrown

Creating a Promise: The Promise object is created using the new keyword and
contains the promise; this is an executor function which has a resolve and a
reject callback. As the names imply, each of these callbacks returns a value with
the reject callback returning an error object.

Screenshot: Using a Promise

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 43/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

The finally() method returns a Promise. When the promise is settled, i.e
either fulfilled or rejected, the specified callback function is executed. This
provides a way for code to be run whether the promise was fulfilled successfully or
rejected once the Promise has been dealt with.
Now, coming to the question,
it asks that when .finally() function will execute. As we know from the above
explanation that it does not matter that promise is resolved or rejected, the .finally()
function will execute every time.

Therefore the correct answer to this question is “When resolved or rejected”

Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally

Pergunta 21: Correto


A 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?
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 44/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

True positive.

False negative. (Correto)

True negative.

False positive.

Explicação
Let’s understand these terms in general.

Let’s take an example where we have a picture and ask you if there is a person or
not in the picture.
This is called binary classification because there are only 2 choices:
• There is a person
• There is not a person
1. True Positive: Image which is a person and you predicted person.
2. True Negative: Images which are not person and you predicted not person.
3. False Positive: Images which are not person and you actually predicted as
person.
4. False Negative: Images which are person but actually predicted not person.

Conclusion:
1. If the prediction is correct, it will be true.
Now, coming back to the question,
the sample code snippet <button>Checkout</button> does not have the class
attribute and the test predicts it correctly.

Pergunta 22: Correto


A developer has the function, shown below, that is called when a page loads.
function onLoad() {
console.log(“Page has loaded!”);
}

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 45/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Where can the developer see the log statement after loading the page in the
browser?

Browser performance tools

Terminal running the web server

On the webpage

Browser javaScript console (Correto)

Explicação
This question is related to the debugging JavaScript code. As a developer, you will
often want to debug code. You might have already used console.log in some of
the challenges, which is the simplest way to debug.

The developer can see the log statements in the browser console. The Browser
Console is like the Web Console, but applied to the whole browser rather than a
single content tab.
Ways to open the Browser Console:
1. Hit F12
2. Ctrl + Shift + I

Screenshot – Browser JavaScript Console

With this explanation,


file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 46/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

the correct answer is “Browser JavaScript console”.

Pergunta 23: Correto


Which statement parses successfully?

JSON.parse(”foo”);

JSON.parse(‘ ”foo” ’); (Correto)

JSON.parse(“ ‘foo’ “);

JSON.parse(‘foo’);

Explicação
Let’s understand few concepts about JSON and JSON.parse() in JavaScript.

JSON stands for JavaScript Object Notation. JSON is an extremely lightweight


data-interchange format for data exchange between server and client which is quick
and easy to parse and generate.

Differences between JSON and JavaScript


While JSON looks like regular JavaScript, it's better to think of JSON as a data
format, similar to a text file. It just so happens that JSON is inspired by JavaScript
syntax, which is why they look so similar.
The main difference between a JSON object and a regular JavaScript object
(object literal) – comes down to the quotation marks. All the keys and string type
values in a JSON object have to be wrapped in double quotation marks (").
JavaScript object literals are a bit more flexible. With object literals, you don't
need to wrap keys and strings in double quotation marks. Instead, you could
use single quotation marks ('), or not use any type of quotation mark for the keys.

Please find the below example for JSON object and JavaScript object

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 47/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Therefore with this explanation, 2 important points to note:


• A JSON object read from these sources enters a Javascript program in a
“flat” string format that contains the object’s key-value pairs wrapped in double-
quotes.
• To create a valid string variable, you must surround the JSON string with
single quotes.

The JSON.parse() method parses a string and returns a JavaScript object.

With this explanation,


the correct answer is JSON.parse(‘ ”foo” ’); because foo is wrapped in double-
quotes, and then the JSON string is surrounded with single quotes.

Please find the code snippet given in question in below example:

Pergunta 24: Correto

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 48/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Cloud Kicks has a class to represent items for sale in an online store, as shown
below:

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?

class ClothingItem extends Item { (Correto)

class ClothingItem super Item {

class ClothingItem implements Item {

class ClothingItem {

Explicação
This question is related to the concept of class inheritance in JavaScript.
• Class inheritance is a way for one class to extend to another class. So we can
create new functionality on top of the existing.
• To create a class inheritance, use the extends keyword.

• A class created with a class inheritance inherits all the methods from another
class
• Super Class (Parent Class): The class whose properties are inherited by sub
class is called Base Class or Super class.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 49/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

• Sub Class (Child Class): The class that inherits properties from another class is
called Sub class or Derived Class.

Please Note:
Inheritance is a mechanism in which one class acquires the property of another
class. For example, a child inherits the traits of his/her parents. With inheritance, we
can reuse the fields and methods of the existing class. Hence, inheritance facilitates
Reusability and is an important concept of OOPs.
Now, coming back to the question,
the requirement is to have ClothingItem class that should have all the properties
and methods of Item class and will also have properties specific to clothes. For this
to work the ClothingItem class should be the Derived Class and Item class should
be the Base Class.
So, here ClothingItem Class should use “extends” keyword

Therefore, the correct answer is:


“class ClothingItem extends Item {“

Pergunta 25: Correto


Refer to the following code:

Which statement should be added to line 09 for the code to display ‘The truck
123AB has a weight of 5000 Ib.'?

super (plate); (Correto)

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 50/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Vehicle.plate = plate;

this.plate = plate;

super.plate = plate;

Explicação
This question is related to Object-Oriented Programming in JavaScript.
The code snippet given in this question uses Class and Constructor in JavaScript.
Few important points to note about constructor in JavaScript.
• The constructor method is a special method of a class for creating and
initializing an object of that class.
• The constructor() method is called automatically when a class is initiated, and
it has to have the exact name "constructor", in fact, if you do not have a constructor
method, JavaScript will add an invisible and empty constructor method.
• A class cannot have more than one constructor() method. This will throw a
SyntaxError.
Screenshot – Sample Code to use constructor in JavaScript

Now, coming back to the question,


we see that the code snippet given in this question uses the concept of inheritance
in JavaScript where the base class (parent class) is Vehicle and sub class (child
class) is Truck.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 51/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Few Important points:


• Inheritance is useful for code reusability: reuse properties and methods of an
existing class when you create a new class.
• The extends keyword is used to create a child class of another class
(parent).
• The child class inherits all the methods from another class.
• By calling the super() method in the constructor method, we call the parent's
constructor method and gets access to the parent's properties and methods.

Screenshot – Code Snippet given in Question with output

With this explanation and screenshot, the correct answer is “super (plate);”

Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Classes/constructor

Pergunta 26: Correto


Given the code below:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 52/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

What is logged to the console?

25134 (Correto)

12534

12435

21435

Explicação
This question is related to the concept of setTimeout() and Promise in JavaScript.

1. setTimeout()
The setTimeout() method allows you to execute a piece of code after a certain
amount of time has passed. You can think of the method as a way to set a timer to
run JavaScript code at a certain time.
For example, the code below will print "Hello World" to the JavaScript console after
2 seconds have passed:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 53/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

2. Promise:
Let’s understand the basics of JavaScript promise. Promises are used to handle
asynchronous operations in JavaScript. They are easy to manage when dealing
with multiple asynchronous operations where callbacks can create callback hell
leading to unmanageable code.
Creating a Promise: The Promise object is created using the new keyword and
contains the promise; this is an executor function which has a resolve and a
reject callback. As the names imply, each of these callbacks returns a value with
the reject callback returning an error object.

In simple words, we can use Promise to perform Asynchronous operation without


disturbing the synchronous operation.
Screenshot – An illustration of the life of promise

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 54/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Promises have three states:


• Pending: This is the initial state of the Promise before an operation begins
• Fulfilled: This means the specified operation was completed
• Rejected: The operation did not complete; an error value is usually thrown

Screenshot – Given Code

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 55/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation,


the correct answer is: “2 5 1 3 4”

Pergunta 27: Correto


A developer has a web server running with Node.js. The command to start the web
server is node server.js. The web server started having latency issues. Instead of a
one-second turnaround for web requests, the developer now sees a five-second
turnaround.
Which command can the web developer run to see what the module is doing during
the latency period?

NODE_DEBUG=true node server.js

DEBUG=http, https node server.js

NODE_DEBUG=http,https node server.js (Correto)

DEBUG=true node server.js


file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 56/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Explicação
There are times when you have a memory leak, or some streams are throwing
uncaught exceptions then a very good tool to have in your arsenal is the
NODE_DEBUG flag.
List of NODE_DEBUG attributes:
• timer
• http
• net
• fs
• cluster
• tls
• stream
• child_process
• module

With this explanation, the correct answer is


“NODE_DEBUG =http, https node server.js”

Pergunta 28: Correto


A developer wrote the following code to test a sum3 function that takes in an array
of numbers and returns the sum of the first three numbers in the array, and the test
passes.

A different developer made changes to the behavior of sum3 to instead sum only
the first two numbers present in the array.
Which two results occur when running this test on the updated sum3 function?
Choose 2 answers.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 57/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

The line 05 assertion passes. (Correto)

The line 02 assertion fails. (Correto)

The line 02 assertion passes.

The line 05 assertion fails.

Explicação
From this question, please notice that a developer made changes to the behavior of
sum3 function to instead sum only the first two numbers present in the array.

At Line 01 – we can see that the array is [1, 4, 1] and the sum of first 2 numbers will
be 5 but the Line 02 is excepting sum to be 6. Therefore the Line 02 assertion
FAILS.
At Line 04 – we can see that the array is [1, 5, 0, 5] and the sum of first 2 numbers
will be 6 and the Line 05 is excepting sum to be 6. Therefore the Line 05
assertion PASSES.

Therefore the correct answers are:


“The line 02 assertion fails”
and
“The line 05 assertion passes”

Pergunta 29: Correto


Refer to the code below:
let textValue = '1984';
Which code segment shows a correct way to convert this string to an integer?

let numberValue = (Number) textValue;

let numberValue = Integer (textValue);

let numberValue = Number (textValue); (Correto)

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 58/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

let numberValue = textValue.toInteger();

Explicação
JavaScript provides various ways to convert a string value into a number. The
best option is to use the Number object, in a non-constructor context (without the
new keyword):

The correct syntax to use Number object is:


const variable_name = Number(‘1234’);
• This takes care of the decimals as well.
• Number is a wrapper object that can perform many operations. If we use the
constructor (new Number ("1234")) it returns us a Number object instead of a
number value, so pay attention.

Please find the below sample code for more clarification:

With this explanation,


the correct answer is: “Let numberValue = Number(textValue);” because this is
the correct syntax to use Number object to convert string value into a number.

The following options are incorrect:


Option “Let numberValue = Integer(textValue);” is NOT correct because this is
invalid. We get ReferenceError: Integer is not defined while using this option.
Option “Let numberValue = textValue.toInteger();” is NOT correct because this is
invalid. We get TypeError: textValue.toInteger() is not a function.
Option “Let numberValue = (Number)textValue;” is NOT correct because this is
not the correct syntax to use the Number Object. The correct syntax is: let

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 59/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

numberValue = Number(textValue);

PRO TIP:
Other Solutions to convert a string value into a number is to use:
• parseInt()
• parseFloat()

Pergunta 30: Correto


Given the code below:

What happens when the code executes?

The url variable has local scope and line 02 throws an error.

The url variable has a global scope and line 02 executes


(Correto)
correctly.

The url variable has a global scope and line 02 throws an error.

The url variable has local scope and line 02 executes correctly.

Explicação
This question is related to the concept of window.location object in JavaScript. The
window.location object can be used to get the current page address (URL) and
to redirect the browser to a new page.
Some examples:
• window.location.href returns the href (URL) of the current page
• window.location.hostname returns the domain name of the web host
• window.location.pathname returns the path and filename of the current
page

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 60/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

• window.location.protocol returns the web protocol used (http: or https:)


• window.location.assign() loads a new document

Few important points about global variable:


• A variable declared outside a function, becomes GLOBAL.
• A global variable has Global Scope. All scripts and functions on a web page
can access it.
• In the above code snippet, url has the global scope

Screenshot – Sample Code snippet given in question with output:

With this explanation and sample code, the correct answer is:
“The url variable has a global scope and LINE 2 executes correctly.”

Pergunta 31: Correto


Given the code below:
const copy = JSON.stringify([ new String(‘ false ’), new Bollean( false ), undefined ]);
What is the value of copy?

“[”false”, { } ]”

“[”false”, false, null]” (Correto)

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 61/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

“[”false”, false, undefined]”

“[false, { } ]”

Explicação
The JSON.stringify() method converts a JavaScript object or value to a JSON
string. It returns a JSON string representing the given value, or undefined.

Now, let’s see the basic code sample below:

From the above sample code and description, few important points to note:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 62/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

1. When we pass undefined as a pure value in JSON.stringify(), it return


undefined.
a. Please observe LINE 8 of code sample and output
2. When we try to convert undefined using JSON.stringify(), then they are either
omitted (when found in an object) or changed to null (when found in an array)
a. Please observe LINE 9 of code sample and output

Now, coming back to question,


the code snippet given is:
const copy = JSON.stringify([ new String(‘ false ’), new Boolean( false ),
undefined ]);

Points to Note:
• JSON.stringify() has input ARRAY with 3 values
• First value is string
• Second value is Boolean
• Third value is undefined (but here undefined is part of Array, so it should
convert as null)

Please find below image having code snippet given in Question & output

With this explanation,


the correct answer is “[”false”, false, null]”

Pergunta 32: Correto


Which option is a core Node.js module?

ios

path (Correto)

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 63/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

locate

memory

Explicação
Module in Node.js is a simple or complex functionality organized in single or
multiple JavaScript files which can be reused throughout the Node.js application.
Each module in Node.js has its own context, so it cannot interfere with other
modules or pollute the global scope. Also, each module can be placed in a separate
.js file under a separate folder.

Node.js includes three types of modules:


1. Core Modules
2. Local Modules
3. Third-Party Modules
This question is about core Node.js module. The core modules include the bare
minimum functionalities of Node.js. These core modules are compiled into their
binary distribution and load automatically when Node.js process starts. However,
you need to import the core module first in order to use it in your application.

From the above explanation,


the correct answer is “path” because “path” is the core module in node.js.

Pergunta 33: Correto

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 64/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

A developer is asked to fix some bugs reported by users. To do that, the developer
adds a breakpoint for debugging.

When the code execution stops at the breakpoint on line 06, which two types of
information are available in the browser console?
Choose 2 answers.

The style, event listeners, and other attributes applied to the


(Correto)
carSpeed DOM element.

The values of the carSpeed and fourWheels variables.

The information stored in the window.localStorage property. (Correto)

A variable displaying the number of instances created for the Car


object.

Explicação
This question is related to the concept of debugger in JavaScript.

The debugger statement invokes any available debugging functionality, such as


setting a breakpoint. If no debugging
functionality is available, this statement has no effect.

When the debugger is invoked, execution is paused at the debugger statement. It


is like a breakpoint in the script source.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 65/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Now, coming back to the question, we can see that the debugger is applied at LINE-
06, therefore the execution will stop at LINE-06. So, it should not have any
information related to fourWheels variable and car object because it is at LINE-07.
So, we can eliminate options:
Option “The values of the carSpeed and fourWheels variables” is NOT correct
because we will not have any
information about fourWheels variable.
Option “A variable displaying the number of instances created for the Car
object” is NOT correct because we will
not have any information about car object.

Therefore, the correct answers are:


“The style, event listeners and other attributes applied to the carSpeed DOM
element.”
and
“The information stored in the window.localStorage property.”

Pergunta 34: Correto


A developer needs to debug a Node.js web server because a runtime error keeps
occurring at one of the endpoints.
The developer wants to test the endpoint on a local machine and make the request
against a local server to look at the behavior. In the source code, the server.js file
will start the server. The developer needs to debug the Node.js server only using
the terminal.
Which command can the developer use to open the CLI debugger in their current
terminal window?

node server.js -- inspect

node -i server.js

node start inspect server.js

node inspect server.js (Correto)

Explicação
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 66/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

This question is related to Node.js. Node.js includes a command-line debugging


utility.
The Node.js debugger client is not a full-featured debugger, but simple stepping and
inspection are possible.

To use it, start Node.js with the inspect argument followed by the path to the script
to debug.
For example: As per Node.js Documentation

With this explanation, the correct answer is:


“node inspect server.js”

Reference:
https://nodejs.org/api/debugger.html
Visit the JavaScript Developer 1 Trailmix on
https://trailhead.salesforce.com/en/users/strailhead/trailmixes/prepare-for-your-
salesforce-javascript-developer-i-credential

Pergunta 35: Correto


Refer to the code below:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 67/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Which code change should be made for the console to log only Row log when ‘Click
me!’ is clicked?

Add event.stopPropagation ( ); to printMessage function. (Correto)

Add event.stopPropagation ( ); to window.onLoad event handler.

Add event.removeEventListner ( ); to printMessage function.

Add event.removeEventListner ( ); to window.onLoad event handler.

Explicação
To answer this question, we need to understand a few concepts in JavaScript.

1. Events
Events are actions that happen when the user or browser manipulates a page. For
example, when the browser finishes loading a document, then a load event
occurred. If a user clicks a button on a page, then a click event has happened.

2. Event Handler

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 68/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

We need event handler to detect when an event happens. This way, we can set up
code to react to events as they happen on the fly.
JavaScript provides an event handler in the form of the addEventListener()
method. This handler can be attached to a specific HTML element you wish to
monitor events for, and the element can have more than one handler attached.

Event.stopPropagation()
The stopPropagation() method of the Event interface prevents further
propagation of the current event in the capturing and bubbling phases.
Now, coming back to the question, the sample code snippet given uses
addEventListener() to handle the “click” event. It calls printMessage() method when
“Click Me!” is clicked.
Also, there is one more “onclick” event handler in table attribute.

Please find the below code snippet and its output:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 69/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Output:

Please find the below code snippet and its output: (Using stopPropagation())

Output:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 70/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation and example, the correct answer is:


Add event.stopPropagation ( ); to printMessage function
Because we have added event.stopPropagation() method in printMessage()
function.

Pergunta 36: Correto


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

const setLocalStorage = (storageKey, jsObject) =>{


window.localStorage.persist(storageKey, jsObject);
}

const setLocalStorage = ( jsObject) =>{


window.localStorage.setItem(jsObject);
}

const setLocalStorage = ( jsObject) => {


window.localStorage.connectObject(jsObject));
}

const setLocalStorage = (storageKey, jsObject) => {


window.localStorage.setItem(storageKey,
(Correto)
JSON.stringify(jsObject));
}

Explicação
First of all, let’s understand about localStorage in JavaScript.

localStorage is a property that allows JavaScript sites and apps to save key-value
pairs in a web browser with no expiration date. This means the data stored in the
browser will persist even after the browser window is closed.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 71/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

The localStorage mechanism is available via the Window.localStorage property.


Window.localStorage is part of the Window interface in JavaScript, which represents
a window containing a DOM document.
The Window interface features a wide range of functions, constructors, objects, and
namespaces. Window.localStorage is a read-only property that returns a reference
to the local storage object used to store data that is only accessible to the origin that
created it.

To use localStorage in your web applications, there are five methods to choose
from:
1. setItem(): Add key and value to localStorage
2. getItem(): This is how you get items from localStorage
3. removeItem(): Remove an item by key from localStorage
4. clear(): Clear all localStorage
5. key(): Passed a number to retrieve the key of a localStorage

Now, coming back to the question,


it is asking about the correct code/syntax used to persist an object in Local Storage.
With this explanation, we can see, there is a method named setItem() to add key,
value to localStorage. Please find below a few points about setItem() method:
• It takes two parameters: a key and a value.
• The key can be referenced later to fetch the value attached to it.
• localStorage can only store strings.
• To store arrays or objects, you would have to convert them to strings.

Screenshot – Sample Code to use setItem() method

With this explanation,


the correct answer is:
const setLocalStorage = (storageKey, jsObject) => {
window.localStorage.setItem(storageKey, JSON.stringify(jsObject));
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 72/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

}
because this option is using setItem() method with key and value parameters.

Pergunta 37: Correto


bar. awesome is a popular JavaScript module. The versions published to npm are:
1.2
1.3.1
1.3.5
1.4.0
Teams at Universal Containers use this module in a number of projects. A particular
project has a package. json definition below.

A developer runs this command: npm install


Which version of bar.awesome is installed?

1.3.1

1.3.5 (Correto)

The command fails because version 1.3.0 is not found.

1.4.0

Explicação
This question is related to installing a specific version of modules. The scenario
given in this question is:
• bar.awesome is a popular Javascript module. The versions published to npm are:
o 1.2

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 73/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

o 1.3.1
o 1.3.5
o 1.4.0
• The package.json definition shows that the dependency for bar.awesome is ~1.3.0

Please Note:
The tilde ~ matches the most recent patch version (the third number) for the
specified minor version (the second number).
~1.3.0 will match all 1.3.x versions but will hold off on 1.4.0.
Here the dependency for bar.awesome is given as ~1.3.0 which will try to match the
most recent patch version and it will match to 1.3.5.
Therefore, the correct answer is:
“1.3.5”

Pergunta 38: Correto


A developer creates a class that represents a blog post based on the requirements
that a Post should have a body, author, and view count.
The code is shown below:

Which statement should be inserted in the placeholder on line 02 to allow for a


variable to be set to a new instance of a Post with the three attributes correctly
populated?

super (body, author, viewCount) {

constructor (body, author, viewCount) { (Correto)

constructor() {

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 74/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

function Post(body, author, viewCount) {

Explicação
This question is related to the constructor method in JavaScript class.
• The constructor() method is a special method for creating and
initializing objects created within a class.
• The constructor() method is called automatically when a class is
initiated, and it has to have the exact name
constructor", in fact, if you do not have a constructor method, JavaScript will add an
invisible and empty constructor method.

Screenshot – Sample Code to use constructor in JavaScript

Screenshot – Sample code given in the question

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 75/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation,


the correct answer to this question is
constructor (body, author, viewCount) {

Pergunta 39: Correto


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

const tls = require('tls');

const https = require('https'); (Correto)

const server = require ('secure-server');

const http = require('http');

Explicação
This question is related to creating a secure web server with node.js.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 76/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

The correct answer is:


“const https = require('https');”

Please refer to the below link for an explanation:


https://nodejs.org/en/knowledge/HTTP/servers/how-to-create-a-HTTPS-server/

Pergunta 40: Correto


The developer has a function that prints "Hello" to an input name. To test this, the
developer 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"?

Change line 9 to sayHello (world) ( );

Change line 2 to console.log('Hello' , name ( ) ); (Correto)

Change line 7 to } ( );

Change line 5 to function world ( ) {

Explicação
This question is related to the concept of Arrow Functions in JavaScript. In
JavaScript, there’s another very simple and concise syntax for creating functions,
that’s often better than Function Expressions. It’s called “arrow functions”.

Screenshot – Syntax of Arrow Function


file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 77/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Screenshot – Example of Arrow Function

Please Note: The syntax of calling an arrow function is variable_name(). For


example,
sum ();
Now, coming back to the question,
please note:
• It uses Arrow Functions.
• The function named world is Arrow Function.
• The function named sayHello is Arrow Function. It accepts a parameter that is
used in console.log ()
• LINE-09, sayHello function is called with parameter as “world” and in LINE-02,
it's using the parameter name to call that function but missing the parenthesis.
• The LINE-02 should be console.log (‘Hello’, name ());

Therefore, the correct answer is:


file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 78/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

“Change line 2 to console.log (‘Hello’, name ());”

Screenshot – Example given in question with correct LINE-02

Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Visit the JavaScript Developer 1 Trailmix on


https://trailhead.salesforce.com/en/users/strailhead/trailmixes/prepare-for-your-
salesforce-javascript-developer-i-credential

Pergunta 41: Correto


A class was written to represent items for purchase in an online store, and a second
class represents items that are on sale at a discounted price. The constructor sets
the name to the first value passed in.

The pseudocode is below:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 79/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

There is a new requirement for a developer to implement a description method that


will return a brief description for Item and SaleItem.

What is the output when executing the code above?

This is a Scarf
Uncaught TypeError: saleItem.description is not a function.
This is a Scarf
This is a discounted Shirt

This is a Scarf
This is a Shirt
This is a discounted Scarf
This is a discounted Shirt

This is a Scarf
This is a Shirt
(Correto)
This is a Scarf
This is a discounted Shirt

This is a Scarf
Uncaught TypeError: saleItem.description is not a function.
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 80/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

This is a Shirt
This is a discounted Shirt

Explicação
This question is related to the concept of Classes in JavaScript which was
introduced with ES6 in 2015. The scenario given in this question is:
• The sample code is given for a class named Item.
• The sample code is given for a class named SaleItem which extends the Item
class

The requirement is to implement a description method that will return a brief


description for Item and SaleItem.
This can be achieved using a prototype in JavaScript. As seen in LINE-03 and
LINE-07, the description methods are added to prototype property.
The output of the sample code will be
This is a Scarf
This is a Shirt
This is a Scarf
This is a discounted Shirt
which is a correct answer.

The sample code is given in Question:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 81/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Output:

Pergunta 42: Correto


Refer 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.

[ ].concat.apply ([ ], inArray); (Correto)

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 82/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

[ ].concat (... inArray); (Correto)

[ ].concat.apply(inArray, [ ]);

[ ].concat ([ ….inArray ] );

Explicação
Let’s understand a few JavaScript concepts involved in this question.

1. Spread Operator & Rest Parameter


Javascript's ECMA6 came out with some cool new features; triple dot (...) is one
of these new Javascript functionalities. It can be used in two different ways; as a
spread operator OR as a rest parameter.
• Rest Parameter
Rest Parameters collect all the remaining elements into an array. With the help of
the rest parameters, we can provide a variable number of arguments to the function.
Let’s assume you need to write a function that can accept dynamic parameters. I.e.
it should handle any no. parameters given.

Please find below the code snippet to get more details.


Screenshot – Sample code with two functions

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 83/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

From the above screenshot, you can see, the function addTwo() uses Rest
Parameter named …args to gather any number of arguments into an array and do
what we want with them.
• Spread Operator
The spread operator allows us to expand elements. With rest parameters
we were able to get a list of arguments into an array. Spread operators
however, let us unpack elements in an array to single/individual arguments.
There are many use cases where we can use spread operator. One of the use
cases is to add array elements to an existing array.

Screenshot – Sample code using Spread Operator

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 84/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

From the above screenshot, you can see, the spread operator is used as …arr to
add elements present in array arr to newArr.

Now, coming back to the question,


few points to note:
1. The array named inArray given in the question is multidimensional array or
nested array i.e. let inArray = [ [1,2], [3,4,5] ]
2. The output we want is a single-dimensional array i.e. [1, 2, 3, 4, 5]

With the above points, it is clear that we need to flatten an array means to reduce
the dimensionality of an array. In simpler terms, it means reducing a
multidimensional array to a specific dimension.
We can achieve this using different ways but we can now focus on a few ways.
1. Using contact() and apply()
In this example,this is an empty array as seen in apply([], arr) and arr is
the argument list we are passing (we’ve defined it above). So, we are saying take
this argument and merge it with what you already got - another empty array, in this
case.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 85/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

2. Using spread operator in ES6


Here, we are using the spread operator to spread out the array. Then concatenate
it with an empty array. For example:

With this explanation,


the correct answers to this question are:
Option “[ ].concat.apply ([ ], inArray);” is correct because it uses contact and
apply way as we seen in above image.
Option “[ ].concat (... inArray);” is correct because it uses spread operator way as
we saw in the above image.

Pergunta 43: Correto


Refer to the code snippet below:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 86/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

What is the value of array after the code executes?

[1, 2, 3, 4, 5, 4, 4]

[1, 2, 3, 4, 5, 4]

[1, 2, 3, 5] (Correto)

[1, 2, 3, 4, 4, 5, 4]

Explicação
This question is related to the Array.splice() method in JavaScript.
Javascript array splice() method changes the content of an array, adding new
elements while removing old elements.

For example:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 87/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Now, coming back to the question, please find below the code snippet:

From the above code snippet:


• The array is [1,2,3,4,4,5,4,4] and the IF condition will be true at index 3.
Array.splice(3,1) means remove one element from index 3. Therefore, the array
becomes [1,2,3,4,5,4,4] and i-- executes so value of i is 2.
• Now, the Array is [1,2,3,4,5,4,4] and current index is 2. IF condition will not
satisfy.
• Now, the Array is [1,2,3,4,5,4,4] and current index is 3. IF condition satisfies.
Therefore Array.splice(3,1) means remove one element from index 3. i.e., the array
becomes [1,2,3,5,4,4] and i-- executes so value of i is 2.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 88/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

• Now, the Array is [1,2,3,5,4,4] and current index is 2. IF condition will not
satisfy.
• Now, the Array is [1,2,3,5,4,4] and current index is 3. IF condition will not
satisfy.
• Now, the Array is [1,2,3,5,4,4] and current index is 4. IF condition satisfies.
Therefore Array.splice(4,1) means remove one element from index 4. i.e., the array
becomes [1,2,3,5,4] and i-- executes so value of i is 3.
• Now, the Array is [1,2,3,5,4] and current index is 3. IF condition will not satisfy.
• Now, the Array is [1,2,3,5,4] and current index is 4. IF condition satisfies.
Therefore Array.splice(4,1) means remove one element from index 4. i.e., the array
becomes [1,2,3,5] and i-- executes so value of i is 3.
• Now the Array is [1,2,3,5] and current index is 3. But it stops here because the
condition i < array.length fail.

With this explanation, the correct answer is: “[1, 2, 3, 5]”

Pergunta 44: Correto


A developer sets up a Node.js server and creates and creates a script at the root of
the source code, index.js, that starts the server when executes.
The developer declares a variable that needs the location and name of the file that
the code executes from.
Which global variable should be used in the script?

window.location

_filename (Correto)

_dirname

this.path

Explicação
This question is related to the concept of global objects in Node.js.
Global Objects:
These objects are available in all modules. The following variables may appear to
be global but are not. They exist only in the scope of modules.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 89/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

• __dirname
• __filename
• exports
• module
• require ()

__filename
The __filename represents the filename of the code being executed. This is the
resolved absolute path of this code file. For the main program, this is not
necessarily the same filename used in the command line. The value inside a
module is the path to that module file.

With this explanation, the correct answer is:


“__filename”

Reference:
https://nodejs.org/docs/latest/api/globals.html#globals_filename

Visit the JavaScript Developer 1 Trailmix on


https://trailhead.salesforce.com/en/users/strailhead/trailmixes/prepare-for-your-
salesforce-javascript-developer-i-credential

Pergunta 45: Correto


Refer to the code below:
Const p1 = 3.1415926;
What is the data type of p1?

Decimal

Double

Number (Correto)

Float

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 90/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Explicação
Let’s understand JavaScript Data Types.

With the above table, the answer to this question should be “Number” but let’s
cross-check using typeof operator also.
typeof is a JavaScript keyword that will return the type of a variable when you call
it. Please find below the sample code for more clarification.

With this explanation,


the correct answer is “Number”.

Pergunta 46: Correto


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

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 91/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

1.2.0 (Correto)

2.0.0

1.2.3

1.1.4

Explicação
This question is related to the concept of Semantic Versioning in JavaScript.

To keep the JavaScript ecosystem healthy, reliable, and secure, every time you
make significant updates to an npm package you own, a new version number of the
package should be given.
Following the semantic versioning spec helps other developers who depend on your
code understand the extent of changes in a given version, and adjust their own
code if necessary.

To help developers who rely on your code, a recommendation is to start your


package version at 1.0.0 and incrementing as follows:

Now, coming back to the question, there are 2 important points:


• The previous version number was 1.1.3
• New features introduced that do not break backward compatibility.

With the given explanation,

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 92/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

we can see the code status is backward compatible with new features and the
Rule is to Increment the middle digit and reset the last digit to zero.
Therefore the correct answer is: 1.2.0

Pergunta 47: Correto


Given the JavaScript below:
01 function filterDOM(searchString) (
02 const parsedSearchString = searchString && searchString.toLowerCase() ;
03 document.querySelectorAll(‘.account’).forEach(account => (
04 const accountName = account.innerHTML. toLowerCase() ;
05 account.style.display = accountName.includes (parsedSearchString) ? /* Insert
code here */;
06 } ) ;
07 }
Which code should replace the placeholder comment on line 05 to hide accounts
that do not match the search string?

‘block’ : ‘none’ (Correto)

‘none’ : ‘block’

‘hidden’ : ‘visible’

‘visible’ : ‘hidden’

Explicação
This question is related to the concept of Display Property in CSS. The Display
property in CSS defines how the components (div, hyperlink, heading, etc) are
going to be placed on the web page. As the name suggests, this property is used to
define the display of the different parts of a web page.

Syntax:
display: value
The below image is showing a handful of values that are commonly used:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 93/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Now, coming back to the question,


in Line 05, we see a question mark (?) symbol. Let’s learn the basics of this symbol.
It is called a conditional operator.
The conditional (ternary) operator is the only JavaScript operator that takes three
operands: a condition followed by a question mark (?), then an expression to
execute if the condition is truthy followed by a colon (:), and finally, the expression
to execute if the condition is falsy. This operator is frequently used as a shortcut for
the if statement.

Now, in the question:


• Condition is to check if the parsedSearchString is present in accountName
• If match, show the account
• Else, hide the account that does not match

With the above explanation,


We know that a display property named none is used to hide/remove the element
and the display property block is used to display the element.
Therefore, the correct answer is

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 94/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

“‘block’: ‘none’” because if the parsedSearchString do not match the account, we


need to hide the element, therefore none is placed after colon (:)

Reference:
https://developer.mozilla.org/en-US/docs/Web/CSS/display

Pergunta 48: Correto


A developer has a web server running with Node.js. The command to start the web
server is node server.js. The web server started having latency issues.
Instead of a one-second turn around for web requests, the developer now sees a
five-second turnaround.
Which command can the web developer run to see what the module is doing during
the latency period?

NODE_DEBUG =http, https node server.js (Correto)

NODE_DEBUG =true node server.js

DEBUG =true node server.js

DEBUG = http, https node server.js

Explicação
There are times when you have a memory leak, or some streams are throwing
uncaught exceptions than a very good tool to have in your arsenal is the
NODE_DEBUG flag.

List of NODE_DEBUG attributes:


• timer
• http
• net
• fs
• cluster
• tls
• stream

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 95/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

• child_process
• module

With this explanation, the correct answer is


“NODE_DEBUG =http, https node server.js”

Pergunta 49: Correto


A developer wants to define a function log to be used a few times on a single-file
JavaScript script.
01 // Line 1 replacement
02 console.log('LOG:', logInput);
03 }
Which two options can correctly replace line 01 and declare the function for use?
Choose 2 answers.

function log(logInput) { (Correto)

function log = (logInput) {

const log(loginInput) {

const log = (logInput) => { (Correto)

Explicação
This question is related to different ways of writing functions in JavaScript. In
JavaScript, we can write functions in 2 ways:

1. The usual way, is by using the function keyword.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 96/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

2. The arrow function syntax


Arrow function is one of the features introduced in the ES6 version of JavaScript. It
allows you to create functions in a cleaner way compared to regular functions.

Screenshot – Example of Arrow Function Syntax

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 97/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation,


the correct answers are:
“function log(logInput) {“ is correct because it uses the function keyword and it’s
the correct syntax.
and
“const log = (logInput) => {“ is correct because it uses the Arrow Function syntax
in correct manner.

The following answers are incorrect:


“const log(loginInput) {“ is not correct because it is neither using function
keyword nor using arrow syntax.
“function log = (logInput) {“ is not correct because this is wrong syntax.

Pergunta 50: Correto


Given the following code:
01 document.body.addEventListener(‘ click ’, (event) => {
02 if (/* CODE REPLACEMENT HERE */) {
03 console.log(‘button clicked!’);
04 )
05 });
Which replacement for the conditional statement on line 02 allows a developer to
correctly determine that a button on page is clicked?

e.nodeTarget ==this
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 98/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Event.clicked

button.addEventListener(‘click’)

event.target.nodeName == ‘BUTTON’ (Correto)

Explicação
To answer this question, we need to understand a few concepts in JavaScript.

1. Events
Events are actions that happen when the user or browser manipulates a page. For
example, when the browser finishes loading a document, then a load event
occurred. If a user clicks a button on a page, then a click event has happened.

2. Event Handler
We need an event handler to detect when an event happens. This way, we can set
up code to react to events as they happen on the fly.
JavaScript provides an event handler in the form of the addEventListener()
method. This handler can be attached to a specific HTML element you wish to
monitor events for, and the element can have more than one handler attached.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 99/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

In thin Syntax, element can be any element in the current DOM or object that
supports event handling like window

3. Arrow Functions in JavaScript


Arrow function is one of the features introduced in the ES6 version of JavaScript. It
allows you to create functions in a cleaner way compared to regular functions.

4. event.target and nodeName


• The event.target property returns which DOM element triggered the event.
• The nodeName property returns the name of the specified node.

Now, coming back to the question, we can observe a few points:


• The code snippet given in the question is using addEventListener() method
• The code snippet given in the question is using arrow function syntax

With this explanation,


the correct answer is “event.target.nodeName == ‘BUTTON’” because the
nodeName property returns the name of the specified node.

Please find the sample code written to alert the nodeName on button click.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 100/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Output:
When the button “Demo Click Event” is clicked, we get the alert as Message =
BUTTON which means the correct answer is “event.target.nodename”

Pergunta 51: Correto


Refer to the code below:
01 let timedFunction = () => {
02 console.log('Timer called.');
03 }:
04
05 let timerId = setTimeout (timedFunction, 1000);
Which statement allows a developer to cancel the scheduled timed function?

clearTimeout (timerId); (Correto)

removeTimeout (timedFunction);

clearTimeout (timedFunction);

removeTimeout (timerId);

Explicação
Let’s understand about setTimeout in JavaScript.

We may decide to execute a function not right now, but at a certain time later. That’s
called “scheduling a call”. One of the options we can use to schedule a call is

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 101/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

setTimeout which allows to run a function once after the interval of time.

Screenshot – Syntax of setTimeout

Screenshot – Sample Code Snippet

Canceling with clearTimeout:


A call to setTimeout returns a “timer identifier” timerId that we can use to
cancel the execution.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 102/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation,


the correct answer is “clearTimeout (timerId);” because we can use
clearTimeout() function with timerId as parameter to cancel the execution.

Pergunta 52: Correto


Given a value, which two options can a developer use to detect if the value is NaN?
Choose 2 answers.

Object.is (value, NaN) (Correto)

value == NaN

value === Number.NaN

isNan (value) (Correto)

Explicação
This question is related to the concept of NaN in JavaScript. JavaScript has the
number type that allows you to represent numbers including integer and floating-
point numbers. And JavaScript number has a special value called NaN, which
stands for Not-a–Number.

The NaN has type number as seen below:

Checking if a value is NaN


1. JavaScript provides you with the global function isNaN() that returns true if its
argument is NaN:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 103/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

2. The Object.is () method can be used to determine whether two values are the
same value.

With this explanation, the correct answers are:


isNaN(value)
and
Object.is(value, NaN)

Pergunta 53: Correto


A developer wants to use a module named universalContainersLib and then call
functions from it.
How should a developer import every function from the module and then call the
functions foo and bar?

import {foo,bar} from '/path/universalContainersLib.js';


foo ( );
bar ( );

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 104/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

import * from '/path/universalContainersLib.js';


universalContainersLib.foo ( );
universalContainersLib.bar ( );

import * as lib from '/path/universalContainersLib.js';


lib.foo ( ); (Correto)
lib.bar ( );

import all from '/path/universalContainersLib.js';


universalContainersLib.foo ( );
universalContainersLib.bar ( );

Explicação
Let’s understand the module in JavaScript.
A module is just a file. One script is one module. as simple as that. Modules can
load each other and use special directives export and import to interchange
functionality, call functions of one module from another one:
• export: keyword labels variables and functions that should be accessible from
outside the current module.
• import: allows the import of functionality from other modules.

There are many different ways we can use the import statements like we can import
specific functions or we can import all the functions. Please find below the list
having all the syntax:

Now, coming back to the question, there are 2 important points to note:
• How should a developer import every function from the module?
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 105/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

• After importing, call function foo() and bar()

With this explanation and the above screenshot syntax, it is clear that to import
every function, we can use asterisk or star symbol (*) with the alias, and then we
can use an alias name to call different functions.
Therefore the correct answer is:
import * as lib from '/path/universalContainersLib.js';
lib.foo ( );
lib.bar ( );
because this is the correct syntax to import every function using asterisk or star
symbol (*) with alias and then call a specific function using an alias name.

Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Statements/import

Pergunta 54: Correto


A developer wants to use a try...catch statement to catch any error that countSheep
() may throw and pass it to a handleError () function.
What is the correct implementation of the try...catch?

try {
setTimeout (function ( ) {
countSheep ( );
} , 1000 );
} catch (e) {
handleError (e);
}

try {
countSheep ( );
} handleError (e) {
catch (e);

try {
countSheep ( );
} finally {
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 106/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

handleError (e);
}

setTimeout (function ( ) {
try {
countSheep ( );
} catch (e) { (Correto)
handleError (e);
}
} , 1000);

Explicação
This question is related to the concept of error handling in JavaScript. No matter
how great we are at programming, sometimes our scripts have errors. They may
occur because of our mistakes, an unexpected user input, an erroneous server
response, and for a thousand other reasons.

Usually, a script “dies” (immediately stops) in case of an error, printing it to console.


But there’s a syntax construct try...catch that allows us to “catch” errors so the
script can, instead of dying, do something more reasonable.
The “try…catch” syntax:

It works like this:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 107/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Now, coming back to the question, we see that they used try…catch block with
setTimeout. Here is the tricky part.
Please Note: try...catch works synchronously
If an exception happens in “scheduled” code, like in setTimeout, then try...catch
won’t catch it. That’s because the function itself is executed later when the engine
has already left the try...catch construct. To catch an exception inside a scheduled
function, try...catch must be inside that function:

Screenshot – Sample Code Snippet from Question

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 108/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation and example, the correct answer is:


setTimeout (function ( ) {
try {
countSheep ( );
} catch (e) {
handleError (e);
}
} , 1000);

Pergunta 55: Correto


A developer has a formatName function that takes two arguments, firstName, and
lastName, and returns a string. They want to schedule the function to run once after
five seconds.
What is the correct syntax to schedule this function?

setTimeout (formatName, 5000, ‘John’, ‘Doe’); (Correto)

setTimeout (‘formatName’, 5000, ‘John’, ‘Doe’);

setTimeout (formatName( ‘John’, ‘Doe’), 5000);

setTimeout (() = > ( formatName( ‘John’, ‘Doe’) ), 5000);

Explicação
Programmers use timing events to delay the execution of certain code or to repeat
code at a specific interval. There are two native functions in the JavaScript library
used to accomplish these tasks:
• setTimeout()
• setInterval()
Few points about setTimeout()
• It is used to delay the execution of the passed function by a specified amount
of time.
• There are two parameters that you pass to setTimeout(): the function you
want to call, and the amount of time in milliseconds to delay the execution of the

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 109/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

function.
• Remember that there are 1000 milliseconds (ms) in 1 second, so 5000 ms is
equal to 5 seconds.
• Syntax of setTimeout()
o setTimeout(function, milliseconds, parameter1, parameter2, . . .
);

Let’s take a sample code snippet example where:


• We have a button ‘Click Me’ onclick of which
• displayMessage() function is called
• This displayMessage() function first call formatName() function using
setTimeout and then call alert.

But when we RUN this code, notice that the sequence of alerts will be:
• Hello Everyone
• Full Name = John Doe

This is because the formatName() function is called after 5000 milliseconds or


5 seconds.

Please find the below code snippet for more clarification:

With this explanation,


the correct answer is
“setTimeout (formatName, 5000, ‘John’, ‘Doe’);” because it uses the correct
syntax.

Pergunta 56: Correto

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 110/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Refer to the code below:


01 let foodMenul = ['Pizza', ‘Burger’, ‘French fries'];
02 let finalMenu = foodMenul;
03 finalMenu.push('Garlic bread’);
What is the value of foodMenul after the code executes?

[‘Garlic bread']

[‘Pizza', 'Burger', 'French fries']

[‘Garlic bread', 'Pizza', 'Burger', ‘French fries']

[‘Pizza', ‘Burger’, ‘French fries’, ‘Garlic bread’] (Correto)

Explicação
Let’s understand a few concepts first:
1. Equal Operator (=) in JavaScript
Arrays in JavaScript are reference values so when you try to copy it using the
EQUAL (=)it will only copy the reference to the original array and not the value of
the array. To create a real copy of an array, you need to copy over the value of the
array under a new value variable. That way this new array does not refer to the old
array address in memory.
2. Mutable and Immutable
An immutable object is an object where the state can't be modified after it is
created. The problem with JavaScript is that arrays are mutable. So this can
happen:

Screenshot – Code Snippet

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 111/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Because Arrays in JavaScript are mutable and reference values, you can see in
the above screenshot, when we use EQUAL (=) operator to copy foodMenul to
finalMenu and if we push anything to finalMenu, its also reflected in foodMunul.

Therefore the correct answer to this question is:


“[‘Pizza', ‘Burger’, ‘French fries’, ‘Garlic bread’]” as you can see in the output of
the above screenshot

Pergunta 57: Correto


Ursa Major Solar (UMS) just launched a new landing page, but users complain that
the website is slow. A developer found some functions that might cause this
problem.
To verify this, the developer decides to execute everything and log the time each of
these three suspicious functions consumes.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 112/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Which function can the developer use to obtain the time spent by every one of the
three functions?

console.trace()

console.timeLog () (Correto)

console.timeStamp ()

console.getTime ()

Explicação
This question is related to measure the time taken by a function to execute in
JavaScript. There are different ways that can be used to calculate the time taken
by the function but the options given are only related to using console methods.

There are a few time-related methods:

Screenshot – Sample code snippet:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 113/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation, the correct answer is


“console.timeLog ()”

Pergunta 58: Correto


Given the following code:
01 let x = null;
02 console.log(typeof x);
What is the output of line 02?

“null”

"x"

"Undefined"

"Object" (Correto)

Explicação
In JavaScript, the typeof operator returns the data type of its operand in the form of
a string. The operand can be any object, function, or variable.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 114/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

The typeof operator is useful because it is an easy way to check the type of
variable in your code. This is important because JavaScript is a dynamically typed
language. This means that you aren’t required to assign types to variables when
you create them. Because a variable is not restricted in this way, its type can
change during the runtime of a program.

The following table summarizes the possible return values of typeof.

Screenshot – Sample code snippet

Now, coming back to the question and given code snippet, the value of variable x
is null and it’s trying to use typeof for variable x.
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 115/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

From the above explanation,


the correct answer is “object”.

Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Operators/typeof

Pergunta 59: Correto


Refer to the code below:
01 const exec = (item, delay) =>
02 new Promise(resolve => setTimeout( () => resolve(item), delay));
03
04 async function runParallel() {
05 const (result1, result2, result3) = await Promise.all{
06 [exec (‘x’, ‘100’) , exec(‘y’, 500), exec(‘z’,‘100’)]
07 );
08 return `parallel is done: ${result1}${result2}${result3}`;
09 }

Which two statements correctly execute the runParallel () function?


Choose 2 answers.

runParallel().then(function(data)
return data;
});

runParallel(). done(function(data){
return data; (Correto)
});

runParallel() .then(data); (Correto)

async runParallel() .then(data);

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 116/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Explicação
Before looking into this question, we need to understand a few concepts in
Javascript.

1. Arrow Function
Arrow functions, introduced in ES6, provide a concise way to write functions in
JavaScript.
Let’s see a few examples with traditional function and function with arrow syntax:

As you can see in the above code snippet image, Arrow Function Syntax – 2
when there is no function body, and only a return value, arrow function syntax
allows you to omit the keyword return as well as the brackets surrounding the
code. This helps simplify smaller functions into one-line statements.

2. Synchronous and Asynchronous JavaScript


1. Synchronous JavaScript: As the name suggests synchronous means to be
in a sequence, so each statement in your code is executed one after the other. This
means each statement has to wait for the previous one to finish executing.
Think of this as if you have just one hand to accomplish 10 tasks. So, you have to
complete one task at a time.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 117/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Let’s look at a sample code snippet for Synchronous JavaScript

2. Asynchronous JavaScript: Asynchronous code takes statements outside of


the main program flow, allowing the code after the asynchronous call to be executed
immediately without waiting.
Here, imagine that for 10 tasks, you have 10 hands. So, each hand can do each
task independently and at the same time.
Let’s look at a sample code snippet for Asynchronous JavaScript

So, from the code snippet of Asynchronous JavaScript, you can see that, it takes 2
seconds to eat ice cream so it’s running in its own thread and the statement -
console.log(‘Ice Cream’) does not wait for the previous statement to execute.
Therefore we call it Asynchronous JavaScript.

There are a few concepts of Asynchronous JavaScript.


1. Callback Function:
In simple terms, calling a function inside another function is called callback. It forms
connections between functions. Let’s assume that to achieve functionality, we need
to perform 2 tasks named taskOne() and taskTwo() so using callback we can
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 118/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

define a relationship between these 2 functions. We can pass taskTwo as a


parameter to taskOne() function and then we can call taskTwo() inside the
taskOne() function. Please find the below code snippet for more details.

Now, let’s assume a few points:


• taskOne is divided into 2 tasks named task1.1 and task1.2.
• Task1.1 takes 3 seconds to complete and Task1.2 takes 2 seconds to
complete.
• After Task1.1 completes, we need to execute Task1.2 and then Task 2.
Therefore we need to use callback and setTimeout as below:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 119/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Note: The callback function is not run unless called by its containing function, it is
called back. Hence, the term callback functions. Multiple functions can be created
independently and used as callback functions. These create multi-level functions.
When this function tree created becomes too large, the code becomes
incomprehensible sometimes and is not easily refactored. This is known as
callback hell.
Callback functions are useful for short asynchronous operations. When working
with large sets, this is not considered best practice. Because of this challenge,
Promises were introduced to simplify deferred activities.

2. Promises
Promises were invented to solve the problem of callback hell and to better handle
our tasks. With Promises, we can defer the execution of a code block until an
asynchronous request is completed. This way, other operations can keep running
without interruption.
Screenshot – An illustration of the life of promise

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 120/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Promises have three states:


• Pending: This is the initial state of the Promise before an operation begins
• Fulfilled: This means the specified operation was completed
• Rejected: The operation did not complete; an error value is usually thrown
Creating a Promise: The Promise object is created using the new keyword and
contains the promise; this is an executor function which has a resolve and a
reject callback. As the names imply, each of these callbacks returns a value with
the reject callback returning an error object.

Let’s see a basic example of promise having finally keyword

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 121/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

3. Async and Await


An async function is a modification to the syntax used in writing promises. You can
call it syntactic sugar over promises. It only makes writing promises easier. Let’s
see the below images to get more details on the difference between using promise
and using Async Await.
Screenshot – Using Promise

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 122/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Screenshot – Using Async Await

Pergunta 60: Correto


Refer to the code below:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 123/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

What is the output after the code executes?

ReferenceError: assignment to undeclared variable "Person"

Developer

ReferenceError: eyeColor is not defined

undefined (Correto)

Explicação
This question is related to “new” keyword in JavaScript.

New keyword in JavaScript is used to create an instance of an object that has a


constructor function. On calling the constructor function with ‘new’ operator, the
following actions are taken:
• A new empty object is created.
• The new object’s internal ‘Prototype’ property (__proto__) is set the same as
the prototype of the constructing function.
• The ‘this’ variable is made to point to the newly created object. It binds the
property which is declared with ‘this’ keyword to the new object.

Now, let’s take the example code given in the question

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 124/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

In the above example, the ‘new’ keyword creates an empty object. Here, Person()
includes three properties ‘firstName’,
‘lastName’, and ‘eyeColor’ are declared with ‘this’ keyword. but, a new empty object
will now include only 2
properties i.e. ‘firstName’, and ‘lastName’ because while initializing the function with
new keyword only firstName and
lastName are given. The newly created objects are returned as myFather().
At LINE 12, you can see the newly created object myFather has only 2 properties.
The third property eyeColor is
undefined as it was not supplied.
Also, there is no property named “job” defined for object Person. So myFather.job
is also Undefined.

Therefore, the correct answer is:


"Undefined"

Pergunta 61: Correto


Refer to the code below:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 125/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

When does Promise.finally on line 08 get called?

When resolved.

When resolved and settled.

When resolved or rejected. (Correto)

When rejected.

Explicação
This question is related to the concept of Promise and Promise.race() static
method in JavaScript. With Promises, we can defer execution of a code block until
an asynchronous request is completed. This way, other operations can keep
running without interruption.

Screenshot – An illustration of the life of promise

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 126/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Promises have three states:


• Pending: This is the initial state of the Promise before an operation begins
• Fulfilled: This means the specified operation was completed
• Rejected: The operation did not complete; an error value is usually thrown

Creating a Promise: The Promise object is created using the new keyword and
contains the promise; this is an executor function which has a resolve and a
reject callback. As the names imply, each of these callbacks returns a value with
the reject callback returning an error object.

Screenshot: Using a Promise

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 127/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

The finally() method returns a Promise. When the promise is settled, i.e
either fulfilled or rejected, the specified callback function is executed. This
provides a way for code to be run whether the promise was fulfilled successfully or
rejected once the Promise has been dealt with.

Now, coming to the question,


it asks that when .finally() function will execute. As we know from the above
explanation that it does not matter that promise is resolved or rejected, the .finally()
function will execute every time.

Therefore the correct answer to this question is “When resolved or rejected”

Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally

Pergunta 62: Correto


A developer implements and calls the following code when an application state
change occurs:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 128/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

If the back button is clicked after this method is executed, what can a developer
expect?

A navigate event is fired with a state property that details the previous
application state.

A popstate event is fired with a state property that details the (Correto)
application's last state.

The page reloads and all JavaScript is reinitialized.

The page is navigated away from and the previous page in the
browser's history is loaded.

Explicação
This question is related to JavaScript window.history.

Let’s understand a few concepts:


1. Window.history
The Window.history read-only property returns a reference to the History object,
which provides an interface for manipulating the browser session history (pages
visited in the tab or frame that the current page is loaded in)

2. History.pushState
Essentially, history.pushState method on the history object can be used to create
and activate a new history entry manually.

3. The event popstate


We have an event called popstate, that occurs when the user goes back to a
history entry point that was created manually using history.pushState or
history.replaceState. This event gets fired on the window object of the DOM.

You can listen to this event by adding an event listener on the window:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 129/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation and POINT – 3, the correct answer is


“A popstate event is fired with a state property that details the application’s
last state”

Visit the JavaScript Developer 1 Trailmix on


https://trailhead.salesforce.com/en/users/strailhead/trailmixes/prepare-for-your-
salesforce-javascript-developer-i-credential

Pergunta 63: Correto


Which option is true about the strict mode in imported modules?

A developer can only reference notStrict() functions from the imported


module.

Imported modules are in strict mode whether you declare


(Correto)
them as such or not.

Add the statement use non-strict; before any other statements in the
module to enable not-strict mode.

Add the statement use strict =false; before any other statements in the
module to enable not- strict mode.

Explicação
Let’s understand the module in JavaScript.
A module is just a file. One script is one module. as simple as that. Modules can
load each other and use special directives export and import to interchange
functionality, call functions of one module from another one:
• export: keyword labels variables and functions that should be accessible
from outside the current module.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 130/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

• import: allows the import of functionality from other modules.

Please find below screenshot showing a basic example:

There is some difference when we use “modules” instead of regular scripts.


Please Note: Modules always work in strict mode. For example: assigning to an
undeclared variable will give an error.

Therefore the correct answer is:


“Imported modules are in strict mode whether you declare them as such or
not” as per the documentation.

Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Statements/import

Visit the JavaScript Developer 1 Trailmix on


https://trailhead.salesforce.com/en/users/strailhead/trailmixes/prepare-for-your-
salesforce-javascript-developer-i-credential

Pergunta 64: Correto


Refer to the code below:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 131/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

What are the values for first and second once the code executes?

first is Why and second is Where. (Correto)

first is Why and second is When.

first is Who and second is Where.

first is Who and second is When.

Explicação
This question has related to the concept of error handling in JavaScript. No
matter how great we are at programming, sometimes our scripts have errors. They
may occur because of our mistakes, an unexpected user input, an erroneous server
response, and for a thousand other reasons.
But there’s a syntax construct try...catch that allows us to “catch” errors so the
script can, instead of dying, do something more reasonable.

The try statement consists of a try-block, which contains one or more


statements. {} must always be used, even for single statements. At least one
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 132/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

catch-block, or a finally-block, must be present. This gives us three forms for


the try statement:

• try...catch
• try...finally
• try...catch...finally

A catch-block contains statements that specify what to do if an exception is thrown


in the try-block. If any statement within the try-block (or in a function called from
within the try-block) throws an exception, control is immediately shifted to the
catch-block. If no exception is thrown in the try-block, the catch-block is
skipped.
The finally-block will always execute after the try-block and catch-block(s)
have finished executing. It always executes, regardless of whether an exception
was thrown or caught.

Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Statements/try...catch

Now, let’s execute the code snippet given in the question:

Output:
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 133/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

With this explanation, the correct answer is


“first is Why and second is Where” because the try…catch…finally sequence will
before second catch block.

Pergunta 65: Correto


Refer to the HTML below:

Which expression outputs the screen width of the element with the ID card-01?

document . getElementById('card-01') .
(Correto)
getBoundingClientRect () . width

document . getElementById('card-01") . width

document . getElementById('card-01') . innerHTML . length*6

document . getElementById('card-01') . style.width

Explicação
The getBoundingClientRect() is a method on Element. It returns an object
that represents the position of the element in the viewport and the width and height
of the element.

For example:

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 134/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Screenshot – Code Example given in Question with output

Output:

With this explanation, the correct answer of the question is:


“document.getElementById("card-01").getBoundingClientRect().width”

Reference:
https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect

Pergunta 66: Correto


Considering type coercion, what does the following expression evaluate to?
true + '13' + NaN

‘true13'
file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 135/137
6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

‘true13NaN' (Correto)

14

‘113NaN’

Explicação
This question is related to the concept of Type Coercion in JavaScript.
Type Coercion refers to the process of automatic or implicit conversion of values
from one data type to another. This includes conversion from Number to String,
String to Number, Boolean to Number, etc. when different types of operators are
applied to the values.

JavaScript calls the toString() method automatically when a Boolean is to be


represented as a text value or when a Boolean is referred to in a string
concatenation.
When any string or non-string value is added to a string, it always converts the non-
string value to a string implicitly. When the string ‘Rahul’ is added to the number 10
then JavaScript does not give an error. It converts the number 10 to string ’10’ using
coercion and then concatenates both the strings. Some more examples are shown
below.

Please find below code example:

With this explanation and example, the correct answer is ‘true13NaN'


because in the given code snippet ‘13’ is a String so, it automatically converts true
and NaN to String making it ‘true13NaN'.

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 136/137


6/22/22, 11:48 AM Salesforce JavaScript Developer 1 - Practice Tests + Explns | Udemy

Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/toString

file:///home/jeff/Desktop/Salesforce JavaScript Developer 1 - Practice Tests + Explns _ Udemy.html 137/137

You might also like