Salesforce Javascript(set 3)

101) Refer to the HTML below:

<div id="main">
						  <div id="card-00">This card is smaller.</div>
						  <div id="card-01">The width and height of this card is determined by its contents.</div>
						</div>

Which statement outputs the height of the element with the ID card-01?

  1. (document.getElementById(‘card-01’).innerHTML.length)/32)*6
  2. document.getElementById(‘card-01’).height
  3. document.getElementById(‘card-01’).getBoundingClientRect().height
  4. document.getElementById(‘card-01’).style.height

102) A developer creates a simple webpage with an input field. When a user enters text in the input field and clicks the button, the actual value of the field must be displayed in the console.

<!-- HTML code -->
						<input type="text" value="Hello" name="input">
						<button type="button">Display</button>
						<!-- JavaScript code -->
						const button document.querySelector("button");
						button.addEventListener('click', () => {
						  const input = document.querySelector('input');
						  console.log(input.getAttribute('value'));
						)}:

When the user clicks the button, the output is always “Hello”. What needs to be done to make this code work as expected?

  1. Replace line 04 with console.log(input.value);
  2. Replace line 03 with const input = document.getElementByName(‘input’);
  3. Replace line 02 with button.addEventListener(“onclick”, function() {
  4. Replace line 02 with button.addCallback(“click”, function() {

103) A developer copied a JavaScript object:

function Person() {
							  this.firstName = "John";
							  this.lastName = "Doe";
							  this.name = () => `${this.firstName), $(this.lastName}`;
							}
							const john = new Person();
							const dan = Object.assign(john);
							dan.firstName = 'Dan';
						

How does the developer access dan’s firstName, lastName? Choose 2 answers.

  1. dan.name
  2. dan.name()
  3. dan.firstName + dan.lastName
  4. dan.firstName() + dan.lastName()

104) Refer to the code below:

flag();
							function flag() {
							  console.log('flag');
							}
							const anotherFlag = () => {
							  console.log('another flag');
							}
							anotherFlag();
						

What is result of the code block?

  1. An error is thrown.
  2. The console logs only ‘flag’.
  3. The console logs ‘flag’ and ‘another flag’.
  4. The console logs ‘flag’ and then an error is thrown.

105) Refer to the code below:

const event = new CustomEvent (
						  //Missing code
						);
						obj.dispatchEvent (event);
					

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

  1. ‘update’, ‘123abc’
  2. ‘update’, {
     detail : {
      recordId: ‘123abc’
     }
    }
  3. ‘update’, {
     recordId: ‘123abc’
    }
  4. {type: ‘update’, recordId: ‘123abc’}

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

const onStateChange = (newPageState) => {
						  window.history.pushState(newPageState, '' ,null);
						}
					

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

  1. The page is navigated away from and the previous page in the browser’s history is loaded.
  2. A popstate event is fired with a state property that details the application’s last state.
  3. A navigate event is fired with a state property that details the previous application state.
  4. The page reloads and all JavaScript is reinitialized.

107) 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?

  1. productSKU = productSKU.padStart(16, ‘0’).padStart(19, ‘sku’);
  2. productSKU = productSKU.padEnd(16, ‘0’).padStart(‘sku’);
  3. productSKU = productSKU.padStart(19, ‘0’).padStart(‘sku’);
  4. productSKU = productSKU.padEnd(16, ‘0’).padStart (19, ‘sku’);

108) Refer to the code below:

function foo() {
						  const a = 2;
						  function bar() {
						    console.log(a);
						  }
						  return bar;
						}
					

Why does the function bar have access to variable a?

  1. Hoisting
  2. Inner function’s scope
  3. Outer function’s scope
  4. Prototype chain

109) Refer to the following code:

function test(val) {
						  if (val === undefined) {
						    return 'Undefined value!';
						  }
						  if (val === null) {
						    return 'Null value!';
						  }
						}
						let x;
						test(x);
					

What is returned by the function call on line 11?

  1. Line 11 throws an error.
  2. ‘Undefined value!’
  3. ‘Null value!’
  4. undefined

110) Which JavaScript methods can be used to serialize an object into a string and deserialize a JSON string into an object, respectively?

  1. JSON.encode and JSON.decode
  2. JSON.stringify and JSON.parse
  3. JSON.serialize and JSON.deserialize
  4. JSON.parse and JSON.deserialize

111) Given the code block below:

function GameConsole(name) {
						  this.name = name;
						}
						GameConsole.prototype.load = function(gamename) {
						  console.log(`$(this.name} is loading a game: $(gamename)...`);
						}
						function Console16bit(name) {
						  GameConsole.call(this, name);
						}
						Console16bit.prototype = Object.create(GameConsole.prototype);
						  // insert code here
						  console.log(`${this.name} is loading a cartridge game: ${gamename}...`);
						}
						const console16bit = new Console16bit('SNEGeneziz');
						console16bit.load('Super Monic 3x Force');
					

What should a developer insert at line 11 to output the following message using the load method?

> SNEGeneziz is loading a cartridge game: Super Monic 3x Force…

  1. Console16bit.prototype.load(gamename)= function() {
  2. Console16bit.prototype.load(gamename) {
  3. Console16bit.prototype.load = function(gamename) {
  4. Console16bit = Object.create (GameConsole.prototype).load = function(gamename) {

112) Refer to the code below:

let a = 'a';
						let b;
						// b = a;
						console.log(b);
					

What is displayed when the code executes?

  1. undefined
  2. ReferenceError: b is not defined
  3. null
  4. a

113) Refer to the code below:

function Person(firstName, lastName, eyeColor) {
						  this.firstName = firstName;
						  this.lastName = lastName;
						  this.eyeColor = eyeColor;
						}
						Person.job = 'Developer';
						const myFather = new Person('John', 'Doe");
						console.log(myFather.job);
					

What is the output after the code executes?

  1. ReferenceError: eyeColor is not defined
  2. TypeError: invalid assignment to const variable Person
  3. undefined
  4. Developer

114) 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”.

const sayHello = (name) => {
						  console.log('Hello', name);
						};
						const world = () => {
						  return 'World';
						};
						sayHello(world);
					

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

  1. Change line 4 to function world() {
  2. Change line 2 to console.log(‘Hello’, name());
  3. Change line 7 to sayHello(world)();
  4. Change line 6 to }();

115) Refer to the following code:

<html lang="en">
						  <div class="outerDiv">
						    <button class="myButton">Click me!</button>
						  </div>
						  <script>
						    function displayInnerMessage(ev) {
						      console.log('Inner message.');
						    }
						    function displayOuterMessage(ev) {
						      console.log('Outer message.');
						    }
						    window.onload = (event) => {
						      document.querySelector('.outerDiv').addEventListener('click', displayOuterMessage, true);
						      document.querySelector('.myButton').addEventListener('click', displayInnerMessage, true);
						    };
						  </script>
						</html>
					

What will the console show when the button is clicked?

  1. Outer message.
  2. Inner message. Outer message.
  3. Inner message.
  4. Outer message. Inner message.

116) Considering type coercion, what does the following expression evaluate to?

true + '13' + NaN

  1. ‘true13NaN’
  2. 14
  3. ‘true13’
  4. ‘113NaN’

Leave a Comment

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