Salesforce Javascript(set 2)

51) A test has a dependency on database.query. During the test the dependency is replaced with an object called database with the method, query, that returns an array. The developer needs to verify how many times the method was called and the arguments used each time.

Which two test approaches describe the requirement? Choose 2 answers.

  1. Integration
  2. Mocking
  3. White box
  4. Black box

52) A developer created a generic function to log custom messages shown in the code below.

						function myLog(message) {
						  console./Answer goes here/('Custom log: ' + message);
						}
					

Which three options can the developer use to log custom messages in the console? Choose 3 answers.

  1. count
  2. group
  3. error
  4. trace
  5. debug

53) Which statement can a developer apply to increment the browser’s navigation history without a page refresh?

  1. window.history.replaceState(newStateObject, ”, null);
  2. window.history.pushState(newstateObject);
  3. window.history.pushState(newStateObject, ”, null);
  4. window.history.state.push(newStateObject);

54) Given the code below:

						const copy = JS0N.stringify([new String('false'), new Boolean(false), undefined]);
					

What is the value of copy?

  1. “[“false”, {}]”
  2. “[false, {}]”
  3. “[“false”, false, undefined]”
  4. “[“false”, false, null]”

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

						class Shoe {
						  constructor(name, price) {
						    this.name = name;
						    this.price = price;
						  }
						  formattedPrice() {
						    return '$' + String(this.price);
						  }
						}
					

A new business requirement comes in that requests a Sneaker class, that should have all of the properties and methods of the shoe class, but will also have properties that are specific to sneakers. Which line of code properly declares the Sneaker class such that it inherits it therits from Shoe?

  1. class Shoe extends Sneaker (
  2. class Sneaker implements Shoe (
  3. class Sneaker extends Shoe (
  4. class Sneaker (

56) Refer to the code below:

						let country = {
						  get capital() {
						    let city = Number("London");
						    return {
						      cityString: city.toString(),
						    }
						  }
						}
					

Which value can a developer expect when referencing country.capital.cityString?

  1. An error
  2. ‘NaN’
  3. undefined
  4. ‘London’

57) A developer has an isDog function that takes one argument, pet. They want to schedule the function to run every minute. What is the correct syntax for scheduling this function?

  1. setTimeout(inDog(‘cat’), 60000);
  2. setInterval(isDog(‘cat’), 60000);
  3. setInterval(isDog, 60000, ‘cat’);
  4. setTimeout(isDog, 60000, ‘cat’);

58) In the browser, the document object is often used to assign variables that require the broadest scope in an application. Node.js applications do not have access to the document object by default.

Which two methods are used to address this? Choose 2 answers

  1. Assign variables to module.exports and require them as needed.
  2. Use the window object instead.
  3. Create a new document object in the root file.
  4. Assign variables to the global object.

59) Refer to the code below:

						x = 3.14;
						function myFunction () {
						  'use strict';
						   y = x;
						}
						z = x;
						myFunction ();
					

Considering the implications of ‘use strict’ on line 03, which three statements describe the execution of the code? Choose 3 answers.

  1. ‘use strict’ has an effect only on line 04.
  2. ‘use strict’ is hoisted, so it has an effect on all lines.
  3. ‘use strict’ has an effect between line 03 and the end of the file.
  4. z is equal to 3.14.
  5. Line 04 throws an error.

60) Given the code below:

						setTimeout(() => {
						  console.log(1);
						}, 1100);
						console.log(2);
						new Promise((resolve, reject) => {
						  setTimeout(() => {
						    reject (console.log(3));
						  }, 1000);
						}).catch(() => {
						  console.log(4);
						});
						console.log(5);
					

What is logged to the console?

  1. 12345
  2. 12534
  3. 25134
  4. 25341

61) A developer is leading the creation of a new web server for their team that will fulfill API requests from an existing client. The team wants a web server that runs on Node.js, and they want to use the new web framework Minimalist.js. The lead developer wants to advocate for a more seasoned back-end framework that already has a community around it. Which two frameworks could the lead developer advocate for?

Choose 2 answers.

  1. Gatsby
  2. Angular
  3. Express
  4. Koa

62) Which function should a developer use to repeatedly execute code at a fixed time interval?

  1. setTimeout
  2. setPeriod
  3. setInterim
  4. setInterval

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

Choose 2 answers

  1. The function generates its own this making it useful for separating the function’s scope from its enclosing scope.
  2. The function uses the this from the enclosing scope.
  3. If the function has a single expression in the function body, the expression will be evaluated and implicitly returned.
  4. The function receives an argument that is always in scope, called parentThis, which is the enclosing lexical scope.

64) Refer to the string below:

						const str = 'Salesforce';
					

Which two statements result in the word ‘Sales’? Choose 2 answers.

  1. str.substr(1, 5);
  2. str.substr(0, 5);
  3. str.substring (1, 5);
  4. str.substring(0, 5);

65) Refer to the following array:

						let arr1 = [1, 2, 3, 4, 5];
					

Which two lines of code result in a second array, arr2, being created such that arr2 is a reference to arr1? Choose 2 answers.

  1. let arr2 = arr1;
  2. let arr2 = arr1.sort();
  3. let arr2 = Array.from (arr1);
  4. let arr2 = arr1.slice(0,5);

66) Given the JavaScript below:

						function filterDOM (searchString) {
						  const parsedSearchString = searchString && searchString.toLowerCase();
						  document.querySelectorAll('.account').forEach (account => {
						    const accountName = account.innerHTML.toLowerCase();
						    account.style.backgroundColor = accountName.includes (parsedSearchString) ? /* Insert code here */;
						  });
						);
					

Which code should replace the placeholder comment on line 05 to highlight accounts that match the search string?

  1. ‘yellow’ : null
  2. null : ‘yellow’
  3. ‘none’ : ‘yellow’
  4. ‘yellow’ : ‘none’

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

						class Item (
						  constructor(name, price) {
						    this.name = name;
						    this.price = price;
						  }
						  formattedPrice() {
						    return '$' + string(this.price);
						  }
						}
					

A new business requirement comes in that requests a clothingItem class, that should have all of the properties and methods of the Item class, but will also have properties that are specific to clothes. Which line of code properly declares the clothingItem class such that it inherits from Item?

  1. class ClothingItem extends Item (
  2. class ClothingItem implements Item (
  3. class ClothingItem {
  4. class ClothingItem super Item (

68) A developer creates an object where it prevents new properties from being added to it and makes all existing properties as non-configurable. Values of present properties can still be changed as long as they are writable.

Which method should be used to execute this business requirement?

  1. Object.freeze();
  2. Object.seal();
  3. Object.lock();
  4. Object.const();

69) Refer to the code below:

						console.log(0);
						setTimeout(() => {
						  console.log(1);
						}, 1000);
						console.log(2);
						setTimeout(() => {
						  console.log(3);
						});
						console.log(4);
					

In which sequence will the numbers be logged?

  1. 01234
  2. 02413
  3. 02431
  4. 13024

70) Refer to the code below:

						const addBy = ?
						const addByEight = addBy (8);
						const sum = addByEight (50);
					

Which two functions can replace line 01 and return 58 to sum? Choose 2 answers

  1. const addBy = (num1) => (num2) => num1 + num2;
  2. const addBy = function(num1) {
      return num1 * num2;
    }
  3. const addBy = (num1) => num1 + num2;
  4. const addBy= function(num1) {
      return function(num2) (
        return num1 + num2;
      }
    }

71) A developer at Universal Containers is creating their new landing page based on HTML, CSS, and JavaScript. The website includes multiple external resources that are loaded when the page is opened. To ensure that visitors have a good experience, a script named personalizeWebsiteContent needs to be executed when the webpage is loaded and there is no need to wait for the resources to be available.

Which statement should be used to call personalizeWebsite Content based on the above business requirement?

  1. window.addEventListener(‘onDOMContentLoaded’, personalizeWebsite Content);
  2. window.addEventListener(“onload”, personalizeWebsiteContent);
  3. window.addEventListener(‘load’, personalize WebsiteContent);
  4. window.addEventListener(‘DOMContentLoaded’, personalizeWebsite Content);

72) Refer to the code below:

						const myFunction = arr => {
						  return arr.reduce((result, current) => {
						  return result + current;
						}, 5)};
					

What is the output of this function when called with an empty array?

  1. Returns 0
  2. Returns 5
  3. Returns NaN
  4. Returns Infinity

73) Refer to the code below:

						const exec (item, delay) =>
						new Promise (resolve => setTimeout(() => resolve(item), delay));
						async function runParallel () {
						  const [result1, result2, result3] = await Promise.all(
						    [exec('x', '100'), exec('y', '500'), exec('2', '100')]
						   );
						   return `parallel is done: ${result1}${result2}${result3}`;
						}
					

Which two statements correctly execute the runParallel() function? Choose 2 answers

  1. runParallel().then(function(data) {
      return data;
    }
  2. runParallel().done(function(data) {
      return data;
    }
  3. runParallel().then(data);
  4. async runParallel().then(data);

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

  1. isNaN(value)
  2. Object.is (value, NaN)
  3. value == NaN
  4. value Number.NaN

75) A developer is setting up a Node.js server and is creating a script at the root of the source code, index.js, that will start the server when executed. The developer declares a variable that needs the folder location that the code executes from.

Which global variable can be used in the script?

  1. __filename
  2. window.location
  3. this.path
  4. __dirname

76) Which three statements are true about promises? Choose 3 answers

  1. A settled promise can become resolved.
  2. A promise has a .then() method.
  3. The executor of a new Promise runs automatically.
  4. A fulfilled or rejected promise will not change states.
  5. A pending promise can become fulfilled, settled, or rejected.

77) A developer removes the checkout button that looked like this:

						<button class='blue'>Checkout</button>
					

There are multiple components in the component with class=’blue’. An existing test verifies the existence of the checkout button, however it looks for a button with class=’blue’. It succeeds because a button with class=’blue’ is found. Which type of test category describes this test?

  1. true positive
  2. false negative
  3. false positive
  4. true negative

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

						import printPrice from /path/PricePrettyPrint.js';
					

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

  1. printPrice must be a multi export
  2. printPrice must be a named export
  3. printPrice must be the default export
  4. printPrice must be an all export

79) Refer to the following object.

						const dog = {
						  firstName: 'Beau',
						  lastName: 'Boo",
						  get fullName() {
						    return this.firstName + '' + this.lastName;
						  }
						};
					

How can a developer access the fullName property for dog?

  1. dog.fullName
  2. dog.fullName()
  3. dog.get.fullName
  4. dog.function.fullName()

80) Refer to the following code:

						let codeName = 'Bond';
						let sampleText = `The name is $(codeName), Jim $(codeName}!`;
					

A developer is trying to determine if a certain substring is part of a string. Which three code statements return true? Choose 3 answers

  1. sampleText.includes(‘Jim’, 4);
  2. sampleText.substring(‘Jim’);
  3. sampleText.includes(‘Jim’);
  4. sampleText.indexOf(‘Bond’) !== -1;
  5. sampleText.includes(‘The’, 1);

81) Refer to the code below.

						function myFunction(true) {
						let x = 1;
						var y = 1;
						if (reassign) (
						  let x = 2;
						  var y = 2;
						  console.log(x);
						  console.log(y);
						}
						console.log(x);
						console.log(y);
					

What is displayed when myFunction(true) is called?

  1. 2222
  2. 2211
  3. 22 undefined undefined
  4. 2212

82) Refer to the code snippet below:

						let array = [1, 2, 3, 4, 4, 5, 4, 4];
						for (let i = 0; i < array.length; i++) {
						  if (array[i] === 4) {
						    array.splice (i, 1);
						  }
						}
					

What is the value of array after the code executes?

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

83) Which two options are core Node.js modules? Choose 2 answers

  1. iostream
  2. worker
  3. http
  4. exception

84) Which two actions can be done using the JavaScript browser console? Choose 2 answers

  1. Run code that’s not related to the page.
  2. Change the DOM and the JavaScript code of the page.
  3. Display a report showing the performance of a page.
  4. View the security cookies.

85) Refer to the code below:

						let timedFunction = () => {
						  console.log('Timer called.');
						};
						let timerId = setInterval(timedFunction, 1000);
					

Which statement allows a developer to cancel the scheduled timed function?

  1. removeInterval(timedFunction);
  2. removeInterval(timerId);
  3. clearInterval(timerId);
  4. clearInterval(timedFunction);

86) Given the code below:

						function Person (name, email) {
						  this.name = name;
						  this.email = email;
						}
						const john = new Person ('John', 'john@email.com');
						const jane = new Person ('Jane', 'jane@email.com');
						const emily = new Person ('Emily', 'emily@email.com');
						let usersList [john, jane, emily];
					

Which method can be used to provide a visual representation of the list of users and to allow sorting by the name or email attribute?

  1. console.info(usersList);
  2. console.groupCollapsed(usersList);
  3. console.group(usersList);
  4. console.table(usersList);

87) Refer to the code below:

						function changeValue(param) {
						  param = 5;
						}
						let a = 10;
						changeValue(a);
						let b = a;
						const result = a + '-' + b;
					

What is the value of result when the code executes?

  1. 5-5
  2. 5-10
  3. 10-5
  4. 10-10

88) Refer to the code below:

						async function functionUnderTest(is0K) {
						  if (is0K) return 'OK';
						  throw new Error('not OK');
						}
					

Which assertion accurately tests the above code?

  1. console.assert(await functionUnderTest(true), ‘not OK”);
  2. console.assert(await(functionUnderTest(true), ‘not OK’));
  3. console.assert(functionUnderTest(true), ‘OK’);
  4. console.assert (await functionUnderTest(true), ‘OK’);

89) Teams at Universal Containers work on multiple JavaScript projects at the same time. They are 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 the teams with npm?

  1. Only local private registries are supported by npm.
  2. Private packages can be scoped and scopes be associated to a private registries.
  3. Private registries are not supported by npm, but packages can be installed locally.
  4. Private packages are not supported in package management.

90) Given the following code:

						counter = 0;
						const logCounter = () => {
						  console.log(counter);
						};
						logCounter();
						setTimeout (logCounter, 2100);
						setInterval (() => {
						  counter++;
						  logCounter();
						), 1000);
					

What will be the first four numbers logged?

  1. 0012
  2. 0112
  3. 0122
  4. 0123

91) A developer is wondering whether to use, Promise.then or Promise.catch, especially when a promise throws an error.

Which two promises are rejected? Choose 2 answers

  1. Promise.reject(‘Cool error here’).then(error => console.error(error));
  2. new Promise((resolve, reject) => {throw ‘cool error here”}).catch(error => console.error(error));
  3. new Promise(() => {throw ‘cool error here’}).then((null, error => console.error(error)));
  4. Promise.reject(‘cool error here’).catch(error > console.error(error));

92) Refer to the code snippet below:

						let array = [1, 2, 3, 4, 4, 5, 4, 4];
						for (let i = 0; i < array.length; i++) {
						  if (array[i] === 4) {
						    array.splice (i, 1);
						    i--;
						  }
						}
					

What is the value of array after the code executes?

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

93) Refer to the following code:

						class Vehicle {
						  constructor(plate) {
						    this.plate = plate;
						  }
						}
						class Truck extends Vehicle {
						  constructor (plate, weight) {
						    //missing code
						    this.weight = weight;
						  }
						  displayWeight() {
						    console.log(`The truck $(this.plate) has a weight of $(this.weight) lb.`);
						  }
						}
						let myTruck = new Truck ('123AB', 5000);
						myTruck.displayWeight();
					

Which statement should be added to line 08 for the code to display ‘The truck 123AB has a weight of 5000 lb.’?

  1. super.plate = plate;
  2. this.plate = plate;
  3. Vehicle.plate = plate;
  4. super(plate);

94) At Universal Containers, every team has its own way of copying JavaScript objects. The code snippet shows an implementation from one team:

						function Person() {
						  this.firstName = "John";
						  this.lastName = "Doe";
						  this.name = () => {
						    console.log(`Hello $(this.firstName) $(this.lastName}`);
						  }
						}
						const john = new Person();
						const dan = JSON.stringify(JSON.parse(john));
						dan.firstName = 'Dan';
						dan.name();
					

What is the output of the code execution?

  1. Hello Dan Doe
  2. Hello John Doe
  3. Hello Dan
  4. SyntaxError: Unexpected token in JSON

95) Given two expressions var1 and var2, what are two valid ways to return the concatenation of the two expressions and ensure it is data type string?

Choose 2 answers

  1. String.concat(var1+var2)
  2. String(var1).concat(var2)
  3. var1.toString()+var2.toString()
  4. varl+var2

96) Refer to the HTML below:

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

Which JavaScript statement changes the text ‘In Progress’ to ‘Completed’?

  1. document.getElementById(“.status”).innerHTML = ‘Completed’;
  2. document.getElementById(“status”).Value = ‘Completed’;
  3. document.getElementById(“#status”).innerHTML = ‘Completed’;
  4. document.getElementById(“status”).innerHTML = ‘Completed’;

97) A developer has code that calculates a restaurant bill, but generates incorrect answers while testing the code.

						function calculateBill(items) {
						  let total = 0;
						  total += findSubtotal(items);
						  total += addTax(total);
						  total += addTip(total);
						  return total;
						}
					

Which option allows the developer to step into each function execution within calculateBill?

  1. Wrapping findSubtotal in a console.log() method.
  2. Calling the console.trace(total) method on line 03.
  3. Using the debugger command on line 03.
  4. Using the debugger command on line 04.

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

						<input type="file" onchange="previewFile()">
						<img src="" height="200" alt="Image preview..."/>
						//The JavaScript portion is:
						function previewFile() {
						  const preview = document.querySelector('img');
						  const file = document.querySelector('input[type=file]').files[0];
						  //line 4
						  reader.addEventListener("load", () => {
						    preview.src=reader.result;
						  }, false);
						  //line 8
						}
					

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?

  1. const reader = new File();
    if (file) reader.readAsDataURL(file);
  2. const reader = new FileReader();
    if (file) URL.createObjectURL(file);
  3. const reader = new File();
    if (file) URL.createObjectURL(file);
  4. const reader = new FileReader();
    if (file) reader.readAsDataURL(file);

99) A test has a dependency on database.query. During the test, the dependency is replaced with an object called database with the method, query, that returns an array. The developer does not need to verify how many times the method has been called.

Which two test approaches describe the requirement? Choose 2 answers

  1. Stubbing
  2. Black box
  3. Substitution
  4. White box

100) Refer to the code below:

						let o = {
						  getjs() {
						    let cityl = String('St. Louis');
						    let city2 = String('New York');
						    return {
						      firstCity: cityl.toLowerCase(),
						      secondCity: city2.toLowerCase(),
						    }
						  }
						}
					

What value can a developer expect when referencing o.js.secondCity?

  1. undefined
  2. ‘new york’
  3. An error
  4. ‘New York’

Leave a Comment

Your email address will not be published. Required fields are marked *