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?
- (document.getElementById(‘card-01’).innerHTML.length)/32)*6
- document.getElementById(‘card-01’).height
- document.getElementById(‘card-01’).getBoundingClientRect().height
- 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?
- Replace line 04 with console.log(input.value);
- Replace line 03 with const input = document.getElementByName(‘input’);
- Replace line 02 with button.addEventListener(“onclick”, function() {
- 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.
- dan.name
- dan.name()
- dan.firstName + dan.lastName
- 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?
- An error is thrown.
- The console logs only ‘flag’.
- The console logs ‘flag’ and ‘another flag’.
- 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
- ‘update’, ‘123abc’
- ‘update’, {
detail : {
recordId: ‘123abc’
}
} - ‘update’, {
recordId: ‘123abc’
} - {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?
- The page is navigated away from and the previous page in the browser’s history is loaded.
- A popstate event is fired with a state property that details the application’s last state.
- A navigate event is fired with a state property that details the previous application state.
- 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?
- productSKU = productSKU.padStart(16, ‘0’).padStart(19, ‘sku’);
- productSKU = productSKU.padEnd(16, ‘0’).padStart(‘sku’);
- productSKU = productSKU.padStart(19, ‘0’).padStart(‘sku’);
- 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?
- Hoisting
- Inner function’s scope
- Outer function’s scope
- 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?
- Line 11 throws an error.
- ‘Undefined value!’
- ‘Null value!’
- undefined
110) Which JavaScript methods can be used to serialize an object into a string and deserialize a JSON string into an object, respectively?
- JSON.encode and JSON.decode
- JSON.stringify and JSON.parse
- JSON.serialize and JSON.deserialize
- 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…
- Console16bit.prototype.load(gamename)= function() {
- Console16bit.prototype.load(gamename) {
- Console16bit.prototype.load = function(gamename) {
- 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?
- undefined
- ReferenceError: b is not defined
- null
- 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?
- ReferenceError: eyeColor is not defined
- TypeError: invalid assignment to const variable Person
- undefined
- 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”?
- Change line 4 to function world() {
- Change line 2 to console.log(‘Hello’, name());
- Change line 7 to sayHello(world)();
- 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?
- Outer message.
- Inner message. Outer message.
- Inner message.
- Outer message. Inner message.
116) Considering type coercion, what does the following expression evaluate to?
true + '13' + NaN
- ‘true13NaN’
- 14
- ‘true13’
- ‘113NaN’