wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JS-Exam

Total questions: 56

Worksheet time: 31mins

Name
Class
Date
1.

1.Given the following code:

document.body.addEventListener(‘ click ’, (event) => {

if (/* CODE REPLACEMENT HERE */) { console.log(‘button clicked!’); )

});

Which replacement for the conditional statement on line 02 allows a developer to correctly determine that a button on page is clicked?

a)

Event.clicked

b)

e.nodeTarget ==this

c)

event.target.nodeName == ‘BUTTON’

d)

button.addEventListener(‘click’)

2.

function Tiger() {

this.Type = 'Cat';

this.size = 'large';

}

let tony = new Tiger();

tony.roar = () => { console.log('Theyre great1'); };

function Lion() {

this.type = 'Cat';

this.size = 'large';

}

17  //Insert code here

18// leo.roar();

Which two statements could be inserted at line 17 to enable the function call on line 18? Choose 2 answers.

a)

leo.roar = () => { console.log(‘They\’re pretty good:’); };

b)

Object.assign(leo,Tiger);

c)

Object.assign(leo,tony);

d)

Leo.prototype.roar = () => { console.log(‘They\’re pretty good:’); };

3.

4. Consider type coercion, what does the following expression evaluate to?

True + 3 + ‘100’ + null

a)

104

b)

4100

c)

‘3100null’

d)

‘4100null’

4.

// 5. Refer to the code below

const pi = 3.1415326;

// What is the data type of pi?

a)

Double

b)

Number

c)

Decimal

d)

Float

5.

// 7. Which statement parses successfully?

a)

JSON. parse ('"foo"')

b)

JSON.parse (""foo'")

c)

JSON.parse ("foo");

d)

JSON.parse ("foo");

6.

10. 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:

a)

Boolean(var1 && var2)

b)

var1 && var2

c)

var1.toBoolean() && var2toBoolean()

d)

Boolean(var1) && Boolean(var2)

7.

11. A developer has an ErrorHandler module that contains multiple functions. What kind of export leverages so that multiple functions can be used?

a)

Named

b)

All

c)

Multi

d)

Default

8.

// 15. 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);

}}

a)

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

b)

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

c)

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

d)

[1, 2, 3, 5]

9.

16. Refer to the code below: let str = ‘javascript’; str[0] = ‘J’; str[4] = ’S’;

After changing the string index values, the value of str is ‘javascript’.

What is the reason for this value:

a)

Non-primitive values are mutable.

b)

Non-primitive values are immutable.

c)

Primitive values are mutable.

d)

Primitive values are immutable.

10.

18. The developer wants to test the array shown:

const arr = Array(5).fill(0)

Which two tests are the most accurate for this array? Choose 2 answers:

a)

console.assert( arr.length === 5 );

b)

arr.forEach(elem => console.assert(elem === 0))

c)

console.assert(arr[0] === 0 && arr[ arr.length] === 0);

d)

console.assert (arr.length >0);

11.

19. Which two console logs outputs NaN? Choose 2 answers

a)

console.log(10/ Number(‘5’));

b)

console.log(parseInt(‘two’));

c)

console.log(10/ ‘five');

d)

console.log(10/0);

12.

22. 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?

a)

printPrice must be be a named export

b)

printPrice must be an all export

c)

printPrice must be the default export

d)

printPrice must be a multi export

13.

// 23. Refer to the code below:

console.log('start');

Promise.resolve('Success').then(function(value){ console.log('Success');

});

console.log('End');

// What is the output after the code executes successfully?

a)

End Start Success

b)

Start Success End

c)

Start End Success

d)

Success Start End

14.

26. Refer to 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 expression outputs the screen width of the element with the ID card-01?

a)

document.getElementById(‘ card-01 ’).getBoundingClientRest().width

b)

document.getElementById(‘ card-01 ’).style.width

c)

document.getElementById(‘ card-01 ’).width

d)

document.getElementById(‘ card-01 ’).innerHTML.length

15.

27. A developer creates an object where its properties should be immutable and prevent properties from being added or modified. Which method should be used to execute this business requirement?

a)

Object.const()

b)

Object.eval()

c)

Object.lock()

d)

Object.freeze()

16.

30. Which three browser specific APIs are available for developers to persist data between page loads? Choose 3 answers

a)

A. IIFEs

b)

B. indexedDB

c)

Global variables

d)

Cookies

e)

localStorage.

17.

34. Refer to 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 values sku 0000000008675309?

a)

productSKU = productSKU .padStart (19. ‘0’).padstart(‘sku’);

b)

productSKU = productSKU .padEnd (16. ‘0’).padstart(‘sku’);

c)

productSKU = productSKU .padEnd (16. ‘0’).padstart(19, ‘sku’);

d)

productSKU = productSKU .padStart (16. ‘0’).padstart(19, ‘sku’);

18.

35. Refer to 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’?

a)

document.getElementById(“status”).Value = ’Completed’;

b)

document.getElementById(“#status”).innerHTML = ’Completed’ ;

c)

document.getElementById(“status”).innerHTML = ’Completed’ ;

d)

document.getElementById(“.status”).innerHTML = ’Completed’ ;

19.

46. 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 turn around 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)

DEBUG = http, https node server.js

b)

NODE_DEBUG =http, https node server.js

c)

DEBUG =true node server.js

d)

NODE_DEBUG =true node server.js

20.

51. Refer to the code below:

let sayHello = () => { console.log ('Hello, world!'); };

Which code executes sayHello once, two minutes from now?

a)

setTimeout(sayHello, 12000);

b)

setInterval(sayHello, 12000);

c)

setTimeout(sayHello(), 12000);

d)

delay(sayHello, 12000);

21.

52. Which three statements are true about promises?

Choose 3 answers

a)

The executor of a new Promise runs automatically.

b)

A Promise has a .then() method.

c)

A fulfilled or rejected promise will not change states .

d)

A settled promise can become resolved.

e)

A pending promise can become fulfilled, settled, or rejected.

22.

56. 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');

23.

57. A developer wants to create an object from a function in the browser using the code below:

function Monster() { this.name = 'hello' };

Line 2: const z = Monster();

What happens due to lack of the new keyword on line 02

a)

The z variable is assigned the correct object.

b)

The z variable is assigned the correct object but this.name remains undefined.

c)

Window.name is assigned to ‘hello’ and the variable z remains undefined.

d)

Window.m is assigned the correct object.

24.

61. A developer is working on an ecommerce website where the delivery date is dynamically calculated based on the current day. The code line below is responsible for this calculation. Const deliveryDate = new Date ();

Due to changes in the business requirements, the delivery date must now be today’s

date + 9 days.

Which code meets this new requirement?

a)

deliveryDate.setDate(( new Date ( )).getDate () +9);

b)

deliveryDate.setDate( Date.current () + 9);

c)

deliveryDate.date = new Date(+9) ;

d)

deliveryDate.date = Date.current () + 9;

25.

71. Universal Container (UC) just launched a new landing page, but users complain that the website is slow. A developer found some functions that cause this problem. To verify this, the developer decides to do everything and log the time each of these three suspicious functions consumes. console.time(‘Performance’);

maybeAHeavyFunction(); thisCouldTakeTooLong(); orMaybeThisOne(); console.endTime(‘Performance’);

Which function can the developer use to obtain the time spent by every one of the three functions?

a)

console.timeLog()

b)

console.getTime()

c)

console.trace()

d)

console.timeStamp()

26.

72. Refer to code below:

Let first = ‘who’; Let second = ‘what’; Try{

Try{ Throw new error(‘Sad trombone’); }catch (err){ First =’Why’; }finally { Second =’when’; } catch (err) { Second =’Where’; } What are the values for first and second once the code executes?

a)

First is Who and second is When

b)

First is why and second is where

c)

First is who and second is where

d)

First is why and second is when

27.

77. Teams at Universal Containers (UC) work on multiple JavaScript projects at the same time.

UC is 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 UC with npm?

a)

Private packages can be scored, and scopes can be associated to a private registries.

b)

Private registries are not supported by npm, but packages can be installed via URL.

c)

Private packages are not supported, but they can use another package manager like yarn.

d)

Private registries are not supported by npm, but packages can be installed via git.

28.

79. Which option is a core Node.js module?

a)

Path

b)

Ios

c)

Memory

d)

locate

29.

91. In which situation should a developer include a try .. catch block around their function call?

a)

The function has an error that should not be silenced.

b)

The function results in an out of memory issue.

c)

The function might raise a runtime error that needs to be handled.

d)

The function contains scheduled code.

30.

94. A developer is debugging a web server that uses Node.js The server hits a runtimeerror every third request to an important endpoint on the web server. The developer added a break point to the start script, that is at index.js at he root of the server’s source code.

The developer wants to make use of chrome DevTools to debug.

Which command can be run to access DevTools and make sure the breakdown is hit?

a)

node -i index.js

b)

Node --inspect-brk index.js

c)

Node inspect index.js

d)

Node --inspect index.js

31.

97. Which statement can a developer apply to increment the browser's navigation history without a page refresh? Which statement can a developer apply to increment the browser's navigation history without a page refresh?

a)

window.history.pushState(newStateObject);

b)

window.history.pushStare(newStateObject, '', null);

c)

window.history.replaceState(newStateObject,'', null);

d)

window.history.state.push(newStateObject);

32.

99. 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);

a)

ReferenceError: eyeColor is not defined

b)

ReferenceError: assignment to undeclared variable “Person”

c)

Developer

d)

Undefined

33.

100. Which statement accurately describes the behaviour of the async/ await keywords?

a)

The associated class contains some asynchronous functions.

b)

The associated function will always return a promise

c)

The associated function can only be called via asynchronous methods

d)

The associated sometimes returns a promise.

34.

101. 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 ()

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 ();

35.

105. Which javascript methods can be used to serialize an object into a string and deserialize a JSON string into an object, respectively?

a)

JSON.stringify and JSON.parse

b)

JSON.serialize and JSON.deserialize

c)

JSON.encode and JSON.decode

d)

JSON.parse and JSON.deserialize

36.

106. Which function should a developer use to repeatedly execute code at a fixed interval?

a)

setIntervel

b)

setTimeout

c)

setPeriod

d)

setInteria

37.

107. Refer to the code below:

function foo () {

const a =2; function bat() {

console.log(a);

} return bar; }

Why does the function bar have access to variable a ?

a)

Inner function’s scope

b)

Hoisting

c)

Outer function’s scope

d)

Prototype chain

38.

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

39.

115. Given the code below: const copy = JSON.stringify([ new String(‘ false ’), new Boolean( false ), undefined ]); What is the value of copy?

a)

[ \”false\” , { } ]--

b)

[ false, { } ]--

c)

[ \”false\” , false, undefined ]-

d)

-- [ \”false\” ,false, null ]--

40.

118. Refer to code below:

function muFunction(reassign){

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?

a)

2 2 1 1

b)

2 2 undefined undefined

c)

2 2 1 2

d)

2 2 2 2

41.

120. Given the following code:

let x =(‘15’ + 10)*2;

What is the value of x?

a)

A. 3020

b)

1520

c)

50

d)

35

42.

123. 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.

43.

124. Refer to the code below:

let timeFunction =() => { console.log(‘Timer called.”); };

let timerId = setTimeout (timedFunction, 1000); Which statement allows a developer to cancel the scheduled timed function?

a)

removeTimeout(timedFunction);

b)

removeTimeout(timerId);

c)

clearTimeout(timerId);

d)

clearTimeout(timedFunction);

44.

126. A developer writers the code below to calculate the factorial of a given number.

function factorial(number) { return number + factorial(number -1);

}

factorial(3);

What is the result of executing line 04?

a)

0

b)

6

c)

-Infinity

d)

RuntimeError

45.

130. Given a value, which three options can a developer use to detect if the value is NaN?

Choose 3 answers

a)

value == NaN

b)

Object.is(value, NaN)

c)

value === Number.NaN

d)

value ! == value

e)

Number.isNaN(value)

46.

131. Which three actions can be using the JavaScript browser console?

Choose 3 answers:

a)

A. View and change DOM the page.

b)

Display a report showing the performance of a page.

c)

Run code that is not related to page.

d)

view , change, and debug the JavaScript code of the page.

e)

View and change security cookies.

47.

132. Considering type coercion, what does the following expression evaluate to? True + ‘13’ + NaN

a)

‘ 113Nan ’

b)

14

c)

‘ true13 ’

d)

‘ true13NaN ’

48.

135. A developer receives a comment from the Tech Lead that the code given below has error:

const monthName = ‘July’; const year = 2019; if(year === 2019) {

monthName = ‘June’; }

Which line edit should be made to make this code run?

a)

let monthName =’July’;

b)

let year =2019;

c)

const year = 2020;

d)

if (year == 2019) {

49.

139. A developer is wondering whether to use, Promise.then or Promise.catch, especially when a Promise throws an error? Which two promises are rejected? Which 2 are correct?

a)

Promise.reject(‘cool error here’).then(error => console.error(error));

b)

Promise.reject(‘cool error here’).catch(error => console.error(error));

c)

New Promise((resolve, reject) => (throw ‘cool error here’}).catch(error => console.error(error)) ;

d)

New Promise(() => (throw ‘cool error here’}).then(null, error => console.error(error)));

50.

140. Given the code below:

Function myFunction(){ A =5; Var b =1; }

myFunction();

//Line 8: console.log(a);

//Line 9: console.log(b);

What is the expected output?

a)

Both lines 08 and 09 are executed, and the variables are outputted.

b)

Line 08 outputs the variable, but line 09 throws an error.

c)

Line 08 thrones an error, therefore line 09 is never executed.

d)

Both lines 08 and 09 are executed, but values outputted are undefined.

51.

156. Given the following code:

Let x =null; console.log(typeof x);

What is the output of the line 02?

a)

“Null”

b)

“X”

c)

“Object”

d)

“undefined”

52.

157. Which option is true about the strict mode in imported modules?

a)

Add the statement use non-strict, before any other statements in the module to enable not-strict mode.

b)

You can only reference notStrict() functions from the imported module.

c)

Imported modules are in strict mode whether you declare them as such or not.

d)

Add the statement use strict =false; before any other statements in the module to enable not- strict mode.

53.

163. 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.firstName)’);

)} Const john = new Person (); Const dan = JSON.parse(JSON.stringify(john)); dan.firstName =’Dan’; dan.name();

What is the Output of the code execution?

a)

Hello Dan Doe

b)

Hello John DOe

c)

TypeError: dan.name is not a function

d)

TypeError: Assignment to constant variable.

54.

// 165: Refer to code below:

const objBook = {

Title: 'Javascript',};

Object.preventExtensions(objBook);

const newObjBook = objBook;

newObjBook.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}

55.

// 168 - What is the value of result?

function changeValue(param) {

param = 5;}

let a = 10; let b = a;

changeValue(b);

const result = a+ '-' + b;

a)

10-10

b)

5-5

c)

10-5

d)

5-10

56.

// 169 Considering that JavaScript is single-threaded, what is the output of line 08 after the code executes?

let total = 10;

const interval = setInterval( () => {

total++ clearInterval(interval); total++;

}, 0)

total++;

a)

10

b)

11

c)

12

d)

13