Salesforce JavaScript Developer 1 - Practice Tests + Explns - 1
Salesforce JavaScript Developer 1 - Practice Tests + Explns - 1
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');
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.
Pergunta 2: Correto
A developer wants to create a simple image upload in the browser using the File
API. The HTML is below:
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?
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.
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(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.
Please find the below screenshot which represents the code snippet given in the
question and its output.
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?
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.
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.
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:
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.
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
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.
References:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new
https://javascript.info/prototype-inheritance
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 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.
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?
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):
PRO TIP:
Other Solutions to convert a string value into a number is to use:
• parseInt()
• parseFloat()
Pergunta 9: Correto
Refer to the code below:
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.
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.
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.
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
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.
Private packages are not supported, but they can use another package
manager like yarn.
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.
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.
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.
'update', {
recordId : '123abc' (Correto)
}
'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.
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
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'
}
}
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?
Explicação
This question is related to different console methods used to log an error.
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.
Please find the below code examples for Node.js and Browser
Example – Node.js
Example – Browser
Explicação
First of all, let’s understand the concept of padStart() and padEnd() methods in
JavaScript.
1. padStart()
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.
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()
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.
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.
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.
0112 (Correto)
0122
0123
0012
Explicação
This question is related to the concept of Arrow Functions, SetTimeout() and
SetInterval() in JavaScript.
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
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() {...}.
With this explanation and code snippet given in the question, we can conclude
that if we use
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
until an asynchronous request is completed. This way, other operations can keep
running without interruption.
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.
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.
Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally
True positive.
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.
Where can the developer see the log statement after loading the page in the
browser?
On the webpage
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
JSON.parse(”foo”);
JSON.parse(‘foo’);
Explicação
Let’s understand few concepts about JSON and JSON.parse() in JavaScript.
Please find the below example for JSON object and JavaScript object
Cloud Kicks has a class to represent items for sale in an online store, as shown
below:
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.
• 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
Which statement should be added to line 09 for the code to display ‘The truck
123AB has a weight of 5000 Ib.'?
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
With this explanation and screenshot, the correct answer is “super (plate);”
Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Classes/constructor
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:
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.
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
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.
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.
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):
numberValue = Number(textValue);
PRO TIP:
Other Solutions to convert a string value into a number is to use:
• parseInt()
• parseFloat()
The url variable has local scope and line 02 throws an error.
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
With this explanation and sample code, the correct answer is:
“The url variable has a global scope and LINE 2 executes correctly.”
“[”false”, { } ]”
“[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.
From the above sample code and description, few important points to note:
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
ios
path (Correto)
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.
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.
Explicação
This question is related to the concept of debugger in JavaScript.
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.
node -i server.js
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
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
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
Which code change should be made for the console to log only Row log when ‘Click
me!’ is clicked?
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 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.
Output:
Please find the below code snippet and its output: (Using stopPropagation())
Output:
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.
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
}
because this option is using setItem() method with key and value parameters.
1.3.1
1.3.5 (Correto)
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
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”
constructor() {
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.
Explicação
This question is related to creating a secure web server with node.js.
What can the developer do to change the code to print "Hello world"?
Change line 7 to } ( );
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”.
Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
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
Output:
[ ].concat.apply(inArray, [ ]);
[ ].concat ([ ….inArray ] );
Explicação
Let’s understand a few JavaScript concepts involved in this question.
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.
From the above screenshot, you can see, the spread operator is used as …arr to
add elements present in array arr to newArr.
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.
[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:
Now, coming back to the question, please find below the code snippet:
• 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.
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.
• __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.
Reference:
https://nodejs.org/docs/latest/api/globals.html#globals_filename
Decimal
Double
Number (Correto)
Float
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.
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.
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
‘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:
Reference:
https://developer.mozilla.org/en-US/docs/Web/CSS/display
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.
• child_process
• module
const log(loginInput) {
Explicação
This question is related to different ways of writing functions in JavaScript. In
JavaScript, we can write functions in 2 ways:
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’)
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.
In thin Syntax, element can be any element in the current DOM or object that
supports event handling like window
Please find the sample code written to alert the nodeName on button click.
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”
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
setTimeout which allows to run a function once after the interval of time.
value == NaN
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.
2. The Object.is () method can be used to determine whether two values are the
same value.
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
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
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.
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:
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
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, . . .
);
But when we RUN this code, notice that the sequence of alerts will be:
• Hello Everyone
• Full Name = John Doe
[‘Garlic bread']
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:
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.
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.
“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.
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.
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
Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Operators/typeof
runParallel().then(function(data)
return data;
});
runParallel(). done(function(data){
return data; (Correto)
});
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.
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.
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
Developer
undefined (Correto)
Explicação
This question is related to “new” keyword in JavaScript.
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.
When resolved.
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.
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.
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.
Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally
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 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.
2. History.pushState
Essentially, history.pushState method on the history object can be used to create
and activate a new history entry manually.
You can listen to this event by adding an event listener on the window:
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.
Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Statements/import
What are the values for first and second once the code executes?
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.
• try...catch
• try...finally
• try...catch...finally
Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Statements/try...catch
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
Which expression outputs the screen width of the element with the ID card-01?
document . getElementById('card-01') .
(Correto)
getBoundingClientRect () . 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:
Output:
Reference:
https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
‘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.
Reference:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/toString