JavaScript Flashcards
(151 cards)
Developer uses the code below to format a date.
const date = new date (2020, 05, 10);
const dateDisplayOptions = {
year: ‘Numeric’,
month: ‘long’,
day: ‘numeric’
};
const formateddate = date.toLocalDateString(‘en’, datedisplayoptions);
After executing, what is the value of formattedDate?
A. May 10, 2020
B. June 10, 2020
C. October 05, 2020
D. November 05, 2020
A
function changeValue(param){
param = 5;
}
let a = 10;
let b = a;
changevalue(b);
const result = a + ‘ - ‘ + b;
What is the value of result when the code executes?
A . 10-10
B . 5-5
C . 10-5
D . 5-10
A
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?
A . NODE_DEBUG=true node server.js
B . DEBUG=http, https node server.js
C . NODE_DEBUG=http,https node server.js
D . DEBUG=true node server.js
D
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 number in the array, The test passes:
Let res = sum2([1, 2, 3 ]) ;
console.assert(res === 6 );
Res = sum3([ 1, 2, 3, 4]);
console.assert(res=== 6);
A different developer made changes to the behavior of sum3 to instead sum all of the numbers present in the array. The test passes:
Which two results occur when running the test on the updated sum3 function ?
Choose 2 answers
A . The line 05 assertion passes.
B . The line 02 assertion passes.
C . The line 02 assertion fails.
D . The line 05 assertion fails.
B, D
Universal Containers (UC) just launched a new landing page, but users complain that the website is
slow. A developer found some functions any 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.
Which function can the developer use to obtain the time spent by every one of the three functions?
console.time(‘Preformance’);
maybeAHeavyFunction();
thisCouldTakeTooLong();
orMAybeThisOne();
console.endtime(‘Preformnce’);
A . console. timeLog ()
B . console.timeStamp ()
C . console.trace()
D . console.getTime ()
A
A test has a dependency on database. query. During the test, the dependency is replaced with an
object called database with the method,
Calculator 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
A . White box
B . Stubbing
C . Black box
D . Substitution
A,D
Given the following code:
01 let x = null;
02 console.log(typeof x);
is the output of line 02?
A . ‘‘x’’
B . ‘‘null’’’
C . ‘‘object’’
D . ‘‘undefined’’
C
Which statement parses successfully?
A . JSON. parse (‘‘foo’’);
B . JSON.parse (‘‘foo’’);
C . JSON.parse (‘foo’);
D . JSON.parse (‘foo’);
A
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?
A . setTimeout (formatName(), 5000, ‘John’, ‘BDoe’);
B . setTimeout (formatName(‘John’, ‘‘Doe’), 5000);
C . setTimout(() => { formatName(‘John’, ‘Doe’) }, 5000);
D . setTimeout (‘formatName’, 5000, ‘John’, ‘Doe’);
D
Which two console logs output NaN?
Choose 2 answers | |
A . console.log(10 / Number(‘5) ) ;
B . console.log(parseInt ‘ (‘two’)) ;
C . console.log(10 / 0);
D . console.loeg(10 / ‘five’);
Answer: B, D
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?
A . import * from ‘/path/universalContainersLib.js’; universalContainersLib. foo ()7
universalContainersLib.bar ();
B . import {foo,bar} from ‘/path/universalCcontainersLib.js’; foo(): bar()?
C . import all from ‘/path/universalContainersLib.js’; universalContainersLib.foo();
universalContainersLib.bar ();
D . import * as lib from ‘/path/universalContainersLib.js’; lib.foo(); lib. bar ();
D
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
A . function leg(logInput) {
B . const log(loginInput) {
C . const log = (logInput) => {
D . function log = (logInput) {
Answer: A, C
Refer to the expression below:
Let x = (‘1’ + 2) == (6 * 2);
How should this expression be modified to ensure that evaluates to false?
A . Let x = (‘1’ + ‘ 2’) == ( 6 * 2);
B . Let x = (‘1’ + 2) == ( 6 * 2);
C . Let x = (1 + 2) == ( ‘6’ / 2);
D . Let x = (1 + 2 ) == ( 6 / 2);
Answer B
A developer implements and calls the following code when an application state change occurs:
Const onStateChange =innerPageState) => {
window.history.pushState(newPageState, ‘ ‘, null);
}
If the back button is clicked after this method is executed, what can a developer expect?
A . A navigate event is fired with a state property that details the previous application state.
B . The page is navigated away from and the previous page in the browser’s history is loaded.
C . The page reloads and all Javascript is reinitialized.
D . A popstate event is fired with a state property that details the application’s last state.
Answer: B
Refer to code below:
console.log(0);
setTimeout(() => (
console.log(1);
});
console.log(2);
setTimeout(() => {
console.log(3);
), 0);
console.log(4);
In which sequence will the numbers be logged?
A . 01234
B . 02431
C . 02413
D . 13024
C
Refer to code below:
Const objBook = {
Title: ‘Javascript’,
};
Object.preventExtensions(objBook);
Const newObjBook = objBook;
newObjectBook.author = ‘Robert’;
What are the values of objBook and newObjBook respectively ?
A . [title: ‘‘javaScript’’] [title: ‘‘javaScript’’]
B . {author: ‘‘Robert’’, title: ‘‘javaScript} Undefined
C . {author: ‘‘Robert’’, title: ‘‘javaScript} {author: ‘‘Robert’’, title: ‘‘javaScript}
D . {author: ‘‘Robert’’} {author: ‘‘Robert’’, title: ‘‘javaScript}
Answer: A
Refer to the following array:
Let arr = [ 1,2, 3, 4, 5];
Which three options result in x evaluating as [3, 4, 5] ?
Choose 3 answers.
A . Let x= arr.filter (( a) => (a<2));
B . Let x= arr.splice(2,3);
C . Let x= arr.slice(2);
D . Let x= arr.filter((a) => ( return a>2 ));
E . Let x = arr.slice(2,3);
Answer: B, C, D
In the browser, the window object is often used to assign variables that require the broadest scope in
an application Node.js application does not have access to the window object by default.
Which two methods are used to address this ?
A . Use the document object instead of the window object.
B . Assign variables to the global object.
C . Create a new window object in the root file.
D . Assign variables to module.exports and require them as needed.
B
Refer to the code below:
Const myFunction = arr => {
Return arr.reduce((result, current) =>{
Return result = current;
}, 10};
}
What is the output of this function when called with an empty array?
A . Returns 0
B . Throws an error
C . Returns 10
D . Returns NaN
Answer: C
Which three browser-specific APIs are available for developers to persist data between page loads ?
Choose 3 answers
A . IIFEs
B . indexedDB
C . Global variables
D . Cookies
E . localStorage.
Answer: A, B, E
A developer has two ways to write a function:
Option A:
function Monster() {
This.growl = () => {
Console.log (‘‘Grr!’’);
}
}
Option B:
function Monster() {};
Monster.prototype.growl =() => {
console.log(‘‘Grr!’’);
}
After deciding on an option, the developer creates 1000 monster objects.
How many growl methods are created with Option A Option B?
A . 1 growl method is created for Option A. 1000 growl methods are created for Option B.
B . 1000 growl method is created for Option A. 1 growl methods are created for Option B.
C . 1000 growl methods are created regardless of which option is used.
D . 1 growl method is created regardless of which option is used.
B
Given the code below:
Setcurrent URL ();
console.log(‘The current URL is: ‘ +url );
function setCurrentUrl() {
Url = window.location.href:
What happens when the code executes?
A . The url variable has local scope and line 02 throws an error.
B . The url variable has global scope and line 02 executes correctly.
C . The url variable has global scope and line 02 throws an error.
D . The url variable has local scope and line 02 executes correctly.
B
Refer to the code below:
let o = {
get js() {
let city1 = String(‘st. Louis’);
let city2 = String(‘ New York’);
return {
firstCity: city1.toLowerCase(),
secondCity: city2.toLowerCase(),
}
}
}
What value can a developer expect when referencing o.js.secondCity?
A . Undefined
B . ‘ new york ‘
C . ‘ New York ‘
D . An error
B
Why would a developer specify a package.jason as a developed forge instead of a dependency ?
A . It is required by the application in production.
B . It is only needed for local development and testing.
C . Other required packages depend on it for development.
D . It should be bundled when the package is published.
B