Last Updated On : 8-Jul-2026
Salesforce Certified JavaScript Developer - JS-Dev-101 Practice Test
Prepare with our free Salesforce Certified JavaScript Developer - JS-Dev-101 sample questions and pass with confidence. Our Salesforce-JavaScript-Developer practice test is designed to help you succeed on exam day.
Salesforce 2026
static delay = async delay = > {
return new Promise(resolve = > {
setTimeout(resolve, delay);
});
};
static asyncCall = async () = > {
await delay(1000);
console.log(1);
};
console.log(2);
asyncCall();
console.log(3);
Assume delay and asyncCall are in scope as functions.
What is logged to the console?
A. 1 2 3
B. 1 3 2
C. 2 1 3
D. 2 3 1
Explanation:
The code executes synchronously first, logging 2 and 3. The asyncCall() function is called but contains await delay(1000), which pauses its execution and returns a pending promise. The setTimeout inside delay schedules the resolution after 1000ms, allowing the synchronous code (console.log(3)) to run first. After 1 second, the promise resolves and console.log(1) executes.
Correct Option:
D: 2 3 1
Step-by-step execution:
console.log(2) runs immediately → logs 2.
asyncCall() is called. Inside asyncCall, await delay(1000) is encountered.
The delay function returns a Promise that resolves after 1000ms. The await pauses asyncCall and returns control to the caller.
console.log(3) runs immediately → logs 3.
After 1000ms, the timeout completes, the Promise resolves, and asyncCall resumes, logging 1.
Final order: 2, 3, 1.
Incorrect Option:
A: 1 2 3
This would occur if asyncCall executed synchronously and completed before console.log(3), which is impossible because await introduces an asynchronous delay.
B: 1 3 2
This would require the delay to be 0ms (or very small) and the event loop to schedule console.log(1) before console.log(3), which does not happen with a 1000ms delay.
C: 2 1 3
This would require the 1000ms delay to complete before console.log(3) runs, but console.log(3) is synchronous and executes immediately after asyncCall() is invoked, not waiting for the promise.
Reference:
MDN Web Docs – "async function": An async function returns a Promise. The await keyword pauses the function execution until the awaited Promise settles, allowing other synchronous code to run in the meantime. The event loop processes microtasks and timers after the synchronous call stack clears.
A page loads 50+ < div class= " ad-library-item " > elements, all ads.
Developer wants to quickly and temporarily remove them.
Options:
A. Use the browser console to execute a script that prevents the load event from firing.
B. Use the DOM inspector to prevent the load event from firing.
C. Use the browser console to execute a script that removes all elements containing the class ad-libraryitem.
D. Use the DOM inspector to remove all elements containing the class ad-library-item.
Explanation:
The browser console allows executing arbitrary JavaScript on the current page. To quickly and temporarily remove all elements with the class ad-library-item, a developer can run a simple DOM manipulation script. This removes the elements instantly without reloading the page. The change is temporary; refreshing the page restores the original content.
Correct Option:
C: Use the browser console to execute a script that removes all elements containing the class ad-library-item.
A script such as document.querySelectorAll('.ad-library-item').forEach(el => el.remove()); immediately removes all matching
Incorrect Option:
A: Use the browser console to execute a script that prevents the load event from firing.
Preventing the load event would not remove existing elements; it might break page functionality. This does not address the requirement of removing ad elements.
B: Use the DOM inspector to prevent the load event from firing.
The DOM inspector is for viewing and editing HTML/CSS structure, not for blocking events. Preventing load events is not possible through the inspector and would not remove existing elements.
D: Use the DOM inspector to remove all elements containing the class ad-library-item.
While possible manually (deleting each element one by one), it is impractical for 50+ elements. The DOM inspector lacks batch removal commands, making this approach slow and inefficient compared to a console script.
Reference:
MDN Web Docs – "Browser Console": The console can execute JavaScript to manipulate the DOM, including batch removal of elements using querySelectorAll() and remove(). This is a quick, temporary solution for testing or ad blocking. The DOM inspector is designed for manual element inspection and single‑element editing.
At Universal Containers, every team has its own way of copying JavaScript objects. The code snippet shows an implementation from one team:
01 function Person() {
02 this.firstName = " John " ;
03 this.lastName = " Doe " ;
04 this.name = () = > {
05 console.log( ' Hello ${this.firstName} ${this.lastName} ' );
06 }
07 }
08
09 const john = new Person();
10 const dan = JSON.parse(JSON.stringify(john)); // (intended deep copy)
11 dan.firstName = ' Dan ' ;
12 dan.name();
(Original line 10 is logically intended to be JSON.parse(JSON.stringify(john)) to perform a JSON clone.)
What is the output of the code execution?
A. Hello John Doe
B. Hello Dan Doe
C. TypeError: dan.name is not a function
D. Hello Dan
Explanation:
JSON.stringify() converts a JavaScript object into a JSON string. When JSON.parse() reconstructs the object, only properties that are JSON‑compatible (strings, numbers, booleans, null, arrays, plain objects) are preserved. Methods (functions) are not part of the JSON format and are omitted. Therefore, dan has no name() function, resulting in a TypeError.
Correct Option:
C: TypeError: dan.name is not a function
JSON.parse(JSON.stringify(john)) creates a new object dan that has properties firstName and lastName (both strings) but loses the name method. Functions cannot be serialized to JSON. When dan.name() is called, dan.name is undefined, so calling it as a function throws a TypeError.
Incorrect Option:
A: Hello John Doe
This would be the output if dan.name() called john.name() or if the copy preserved methods. However, dan has no name method, so this does not occur.
B: Hello Dan Doe
This would require dan to have a name() method that uses dan.firstName = 'Dan'. Since the method is lost, this is impossible.
D: Hello Dan
This is also impossible because the method does not exist on dan. No string output is produced; an error is thrown instead.
Reference:
MDN Web Docs – "JSON.stringify()": Functions, undefined, and symbols are not valid JSON values and are omitted (or replaced with null in arrays). JSON.parse() recreates only the JSON‑compatible data, discarding any non‑serializable properties. For deep copying objects with methods, use structured cloning (e.g., structuredClone() in modern JS) or recursive copy functions.
Which three actions can the code execute in the browser console?
A. Run code that is not related to the page.
B. View and change security cookies.
C. Display a report showing the performance of a page.
D. View, change, and debug the JavaScript code of the page.
E. View and change the DOM of the page.
D. View, change, and debug the JavaScript code of the page.
E. View and change the DOM of the page.
Explanation:
The browser console is a powerful developer tool that allows interaction with the currently loaded web page. It can execute arbitrary JavaScript (including code not directly related to the page), debug and modify the page's JavaScript, and manipulate the DOM in real time. However, security restrictions apply to certain operations like accessing secure cookies.
Correct Option:
A: Run code that is not related to the page.
The console can execute any JavaScript expression, regardless of whether it interacts with the page. For example, 2 + 2 or console.log('Hello') run independently of the page's context.
D: View, change, and debug the JavaScript code of the page.
The console allows inspection of global variables, functions, and objects. You can override functions, set breakpoints (via Sources tab), and execute modified code to test changes dynamically.
E: View and change the DOM of the page.
Using the console, you can access the DOM via document object, modify elements (document.querySelector('h1').innerText = 'New Text'), add/remove nodes, and see changes reflected immediately on the page.
Incorrect Option:
B: View and change security cookies.
Modern browsers restrict access to HttpOnly cookies for security reasons. While document.cookie can read non-HttpOnly cookies, security cookies (e.g., session cookies with HttpOnly flag) cannot be accessed or modified via JavaScript console.
C: Display a report showing the performance of a page.
Performance reports are generated using the Performance tab in DevTools, not the console. While console can use console.time() or performance API, it does not display comprehensive performance reports like the dedicated Performance panel.
Reference:
MDN Web Docs – "Browser Console": The console allows executing arbitrary JavaScript, interacting with the DOM, and debugging code. Cookies with HttpOnly flag are inaccessible for security. Performance profiling requires the Performance panel, not the console alone.
Refer to the code below:
const searchText = ' Yay! Salesforce is amazing! ' ;
let result1 = searchText.search(/sales/i);
let result2 = searchText.search(/sales/);
console.log(result1);
console.log(result2);
After running this code, which result is displayed on the console?
A. 5
undefined
B. 5
0
C. true
false
D. 5
-1
-1
Explanation:
The search() method returns the index of the first match of a regular expression within a string, or -1 if no match is found. The first regex /sales/i is case-insensitive (i flag), so it matches "Sales" (capital S) at index 5. The second regex /sales/ is case-sensitive, and since the string contains "Sales" (capital S) not "sales" (lowercase s), it returns -1.
Correct Option:
D: 5 and -1
Step-by-step:
searchText = 'Yay! Salesforce is amazing!'
Character positions: Y(0) a(1) y(2) !(3) space(4) S(5) a(6) l(7) e(8) s(9)...
/sales/i ignores case → matches "Sales" starting at index 5 → result1 = 5.
/sales/ is case-sensitive → no lowercase "sales" found → result2 = -1.
Console outputs 5 then -1.
Incorrect Option:
A: 5 and undefined
search() never returns undefined; it returns an integer index or -1. This is incorrect.
B: 5 and 0
0 would indicate a match at the very beginning of the string. There is no match for /sales/ at index 0 because the string starts with "Yay! ".
C: true and false
search() returns numeric indices, not boolean values. This would be true for test() or exec() methods, not search().
Reference:
MDN Web Docs – "String.prototype.search()": The search() method executes a search for a match between a regular expression and the string object. It returns the index of the first match, or -1 if not found. The i flag makes the regex case-insensitive.
| Salesforce-JavaScript-Developer Exam Questions - Home | Previous |
| Page 8 out of 55 Pages |