JavaScript-Developer-I Practice Test Questions

221 Questions


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


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


B. -- [ false, { } ]--


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


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





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

Explanation:

When JSON.stringify processes an array:

1. String object: new String('false') is coerced to the primitive "false", so it becomes the JSON string "false".
2. Boolean object: new Boolean(false) is coerced to the primitive false, so it becomes the JSON boolean false.
3. Undefined: Array elements that are undefined are serialized as null in JSON.

Putting this together yields the JSON text ["false",false,null].

Universal Containers recently launched its new landing page to host a crowd-funding campaign. The page uses an external library to display some third-party ads. Once the page is fully loaded, it creates more than 50 new HTML items placed randomly inside the DOM, All the elements includes the same ad-library-item class, They are hidden by default, and they are randomly displayed while the user navigates through the page.


A. Use the DOM inspector to prevent the load event to be fired.


B. Use the browser to execute a script that removes all the element containing the class ad-library-item.


C. Use the DOM inspector to remove all the elements containing the class ad-library-item.


D. Use the browser console to execute a script that prevents the load event to be fired.





B.
  Use the browser to execute a script that removes all the element containing the class ad-library-item.

Explanation:

Since the ads are generated dynamically after load and may reappear randomly, manually deleting them via the DOM inspector (option C) is impractical and one-off. Preventing the load event (options A and D) could break page functionality. Instead, injecting a small JavaScript snippet in the browser console to select all elements with .ad-library-item and remove them ensures you can rerun it at any time to clean up all current and newly inserted ads. For example:
document.querySelectorAll('.ad-library-item').forEach(el => el.remove());

Given HTML below:
1. Universal Container
2. Applied Shipping
3. Burlington Textiles

Which statement adds the priority = account CSS class to the universal Containers row ?


A. Document .querySelector(‘#row-uc’).classes.push(‘priority-account’);


B. Document .queryElementById(‘row-uc’).addclass(‘priority-account’);


C. Document .querySelector(‘#row-uc’).classList.add(‘priority-account’);


D. Document .querySelectorALL(‘#row-uc’).classList.add(‘priority-account’);





C.
  Document .querySelector(‘#row-uc’).classList.add(‘priority-account’);

Explanation:

The document.querySelector('#row-uc') call returns the

element with id="row-uc". Its classList property provides a DOMTokenList of all classes on the element, with an add(...) method to append a new class without disturbing existing ones. Option A is invalid because there’s no .classes property or .push() on DOM elements. Option B mistypes getElementById and uses a non-existent .addclass(). Option D calls querySelectorAll, which returns a NodeList; you’d then need to iterate over each node to add the class.

Which two code snippets show working examples of a recursive function?
(Choose 2 answers)


A. Let countingDown = function(startNumber) {
If ( startNumber >0) {
console.log(startNumber) ;
return countingDown(startNUmber);
} else {
return startNumber;
}};


B. Function factorial ( numVar ) {
If (numVar < 0) return;
If ( numVar === 0 ) return 1;
return numVar -1;


C. Const sumToTen = numVar => {
If (numVar < 0)
Return;
return sumToTen(numVar + 1)};


D. Const factorial =numVar => {
If (numVar < 0) return;
If ( numVar === 0 ) return 1;





A.
  Let countingDown = function(startNumber) {
If ( startNumber >0) {
console.log(startNumber) ;
return countingDown(startNUmber);
} else {
return startNumber;
}};

D.
  Const factorial =numVar => {
If (numVar < 0) return;
If ( numVar === 0 ) return 1;

Explanation:

Option A shows a proper recursive countdown function that:
Has a base case (startNumber <= 0)
Makes a recursive call with a modified parameter (startNumber - 1)
Actually progresses toward the base case

Option D shows a correct factorial function that:
Handles edge cases (negative numbers and 0)
Recursively calls itself with numVar - 1
Combines results with multiplication (numVar * factorial(numVar - 1))

Refer to the code below:
new Promise((resolve, reject) => {
const fraction = Math.random();
if( fraction >0.5) reject("fraction > 0.5, " + fraction);
resolve(fraction);
})
.then(() =>console.log("resolved"))
.catch((error) => console.error(error))
.finally(() => console.log(" when am I called?"));

When does Promise.finally on line 08 get called?


A. When rejected


B. When resolved and settled


C. When resolved


D. When resolved or rejected





D.
  When resolved or rejected

Explanation:

The .finally() method of a Promise is guaranteed to execute once the promise is settled, regardless of whether it was fulfilled or rejected. It does not receive any arguments, and is designed for cleanup tasks (such as hiding loading indicators) that must run in either case. In the code above, if fraction > 0.5, the promise is rejected and the .catch() handler runs first; whether through .then() or .catch(), once that branch completes, .finally() executes. Thus, line 08 always logs "when am I called?" after the promise has either resolved or rejected.

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





C.
  Returns 10

Explanation:

When you call Array.prototype.reduce on an empty array with an initial value provided (10), the reducer function is never invoked, and reduce immediately returns that initial value. In this snippet, because arr is empty, reduce skips the callback and yields 10. No error is thrown, and you don’t get NaN (which would happen if you’d attempted arithmetic without an initial value). Always remember: with an initial accumulator, reduce guarantees a return value even for empty arrays.

Refer to HTML below:
This card is smaller.
The width and height of this card is determined by its contents.
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.lenght*e





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

Explanation:

The only reliable way to obtain an element’s on-screen dimensions (including padding and borders) is via the getBoundingClientRect() method, which returns a DOMRect containing width and height properties. Accessing style.width only reflects inline CSS, not the computed on-screen width. There is no direct width property on DOM elements, and calculating width via innerHTML.length is both inaccurate and unrelated to actual layout size. Therefore, calling getBoundingClientRect().width on the element with ID card-01 correctly returns its rendered width in pixels.

Which option is a core Node,js module?


A. Path


B. Ios


C. Memory


D. locate





A.
  Path

Explanation:

Node.js is built on a minimal set of “core” modules that ship with every installation, eliminating the need to install them separately. The path module provides utilities for working with file and directory paths in a platform-agnostic way—handling separators, extensions, and normalization. Neither Ios, Memory, nor locate exist as built-in modules in Node.js’s standard library. By importing path (const path = require('path');), you gain access to methods like path.join(), path.resolve(), and path.basename(), making it the correct and only core module listed.

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





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



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.

A. Non-primitive values are mutable.


B.

Non-primitive values are immutable.


C.

Primitive values are mutable.


D.

Primitive values are immutable.





D.
  

Primitive values are immutable.



Which three actions can be using the JavaScript browser console?
Choose 3 answers:


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





A.
  

View and change DOM the page.



C.
  

Run code that is not related to page.



D.
  

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



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





C.
  

Start
End
Success




Page 3 out of 19 Pages
Previous