







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This collection offers questions and answers for the Salesforce JavaScript Developer exam, covering array manipulation, data types, object methods, class declarations, import/export, decorators, and debugging. Designed to test JavaScript understanding within Salesforce, it provides insights and practical knowledge for exam prep and skill enhancement. Code snippets and explanations aid comprehension and application. It's useful for developers preparing for the exam, offering a focused approach to mastering key concepts and techniques. It serves as a tool for self-assessment and knowledge reinforcement, helping developers identify areas for improvement within the Salesforce ecosystem.
Typology: Exams
1 / 13
This page cannot be seen from the preview
Don't miss anything!








A developer needs to pass an array as an argument, the current variable looks like an array but is not one. What can be used to convert this variable into an array? - Correct Answers -let arrayVar = Array.from(myVar); const array1 = [1, 2, 3, 4]; const reducer = (accumulator, currentValue) => accumulator + currentValue; console.log(array1.reduce(reducer)); - Correct Answers - Name two methods used to access Coordinated Universal Time, method converts a date to a string. - Correct Answers -toISOString(); toUTCString(); Destructing Assignment Syntax const hero = { name: 'Batman', realName: 'Bruce Wayne' }; const {_____________________ } = hero; name; // => 'Batman', realName; realName; // => 'Bruce Wayne' - Correct Answers -name, realName Combining two arrays: const cars = ["Saab", "Volvo", "BMW"]; var food = ["pizza", "tacos", "burgers"]; - Correct Answers -["Saab", "Volvo", "BMW", ...food]; What would this return? let num; if(num == '' || num == null) { num = true; } return num; - Correct Answers -true let fake; console.log((fake == 0)); //false
console.log((fake == null)) // true What would this return? let count = null; if(count == undefined && count== null) { count = true; } return count; - Correct Answers -true So: undefined == null What would this return? let count = null; if(count == "" && count== null) { count = true; } return count; - Correct Answers -null let fruit = [{type: 'Apple', price: 1.99, quantity: 3}, {type: 'Pear', price: 2.59, quantity: 2} ]; const cost = fruit.reduce((accumulator, currentValue) => {return(accumulator + currentValue.price *currentValue.quantity)}, 0); - Correct Answers -11.15 (correct total) What is the symbol data type? - Correct Answers -Symbol is a built-in object whose constructor returns a symbol primitive โ also called a Symbol value or just a Symbol โ that's guaranteed to be unique. Symbols are often used to add unique property keys to an object that won't collide with keys any other code might add to the object, and which are hidden from any mechanisms other code will typically use to access the object. That enables a form of weak encapsulation, or a weak form of information hiding. Every Symbol() call is guaranteed to return a unique Symbol. Every Symbol.for("key") call will always return the same Symbol for a given value of "key". When Symbol.for("key") is called, if a Symbol with the given key can be found in the global Symbol registry, that Symbol is returned. Otherwise, a new Symbol is created, added to the global Symbol registry under the given key, and returned. In JS, null == undefined - Correct Answers -true In JS, 0 == undefined - Correct Answers -false In JS, 0 == false - Correct Answers -true What is wrong with this code? class Car { constructor(brand) {
True or False: A decorator function can extend class methods. - Correct Answers -true - it can extend them What is this an example of? app.get('/example/a', function (req, res) { res.send('Hello from A!') }) (Exam Example) - Correct Answers -An express routing handler, a single callback function to handle a route If more than one parameter needs to be specified, use a semicolon, /example/:timePair Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (GET, POST, and so on). _____________ is a method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. (Exam Example) - Correct Answers -flat( ) _________ is actually nothing more than functions that return another function - Correct Answers -Decorators What is the technical error with this declaration? const userData = () => { return '${this.name} - ${this.getAge()}';} - Correct Answers - None - arrow functions can be used to bind the this keyword to an object in the scope that does not depend on how function was invoked Generator functions return a generator that can be used with .next allowing access to each item. This makes them idea repeated random number generation. - Correct Answers -True True or false: Multiple decorators can be used on class methods and properties? - Correct Answers -True What do each of the following do? Object.seal( ); Object.freeze( ); Object.preventExtensions( ); Object.create( ); - Correct Answers -seal - can't add or delete , can change existing preventExtensions - can change properties or delete, cannot add new ones freeze - no changes create - new object JS decorator functions are passed three arguments, what are they? - Correct Answers - target is the class that our object is an instance of. key is the property name, as a string, that we're applying the decorator to.
descriptor is that property's descriptor object. Only one parameter is passed to a decorator when used to decorate a class, this parameter is the target object which is the class that is being decorated. - Correct Answers -True Where would the following be used? export {getAges} from './customer/utility.js'; - Correct Answers -In a passthrough module to allow other classes to easily access a number of different exported data, the from allows this to be done without writing an import line in the passthrough function itself, from like used during imports __________ is an Array-like object accessible inside functions that contains the values passed to a function. - Correct Answers -arguments function func1(a, b, c) { console.log(arguments[0]); function handle(request, Closure $next , ...guards) { When the function is called with more than 3 arguments, all the arguments after $next will be added to the $guards array. Arguments object is an ________-like collections of values. The arguments object contains __________ values passed to the function. The arguments object is only available for _________________ functions. - Correct Answers -array-like all the values non-arrow functions What will need to be added since the prototype is lost during object instantiation. myFruits.prototype = Object.create(Fruits.prototype); - Correct Answers -The constructor, inheritance will set a structure but the constructor need to be added manually. Object.defineProperty(myFruit.prototype, 'constructor', {value: myFruits, enumerable: false, wriable: true }); True false: All items must be named when importing multiple from a module that names exports - Correct Answers -True True or False: SetTimeout( ) is only called if the stack is empty, all other messages have been processed, and then it is called x milliseconds after that. - Correct Answers - True What would the following output? let ratings = [5, 4, 3]; ratings.forEach((element) => { console.log(element) } )
kill: Kill script Various# scripts: List all loaded scripts version: Display V8's version - Correct Answers -Node.js _____________: the class that represents an independent JavaScript execution thread. isMainThread : a boolean that is true if the code is not running inside of a Worker thread. parentPort : the MessagePort allowing communication with the parent thread If this thread was spawned as a Worker. - Correct Answers -Worker The global property Infinity is a numeric value representing infinity. - Correct Answers - infinity console.log('e: ' + (true + 3 + 'hi' + null)); (Exam Example) - Correct Answers -4hinull console.log('e: ' + (null + 'hi' + null)); // e: nullhinull console.log('e: ' + (null + 3 + 'hi' + null)); // e: 3hinull console.log('Hello, world!') function myIsNaN(num) { if(num == null){ return 0; } if(num2 == 3){ return 3; } } console.log('e: ' + myIsNaN(2)); console.log('e: ' + myIsNaN(2)(3)); - Correct Answers -errors console.log('Hello, world!'); class Polygon { constructor() { this.name = 'yo'; } fred = function() { let x = 'y'; } } let p = new Polygon(); console.log('e: ' + p.fred); //(Possible Exam Example) - Correct Answers -//Output:
Hello, world! e: function() { let x = 'y'; } You can change properties of even constant declared objects console.log('Hello, world!') class Polygon { constructor() { this.name = 'yo'; } fred = function() { let x = 'y'; } } const p = new Polygon(); p.name = 'dude'; console.log('e: ' + p.name); (Exam Example) - Correct Answers -True let obj = JSON.parse(JSON.stringify(myObj)); obj.name = 'fred'; document.getElementById("demo").innerHTML = obj.name; (Exam Example) - Correct Answers -output: fred Node.js server with error handling: let server = new Websocket(path, opts) server._____ _____ What is the rest? (Exam Example) - Correct Answers -.on('error', (error) => { //handle error }) JS Debugging: Name 3 ways to do this. (Exam Example) - Correct Answers -1. set in chrome
getResult(); - Correct Answers -Correct. Using await inside the function causes both to execute. const p1 = new Promise((resolve, reject) => { setTimeout(() => { resolve('P1 Resolved'); }, 1500); }); const p2 = (data) => new Promise((resolve, reject) => { setTimeout(() => resolve('$ {data}, P2 Resolved'), 1500, data); }); (Trailhead Question) Would the following correctly execute the code? A p1.then((data) => p2(data)).then(result => result); - Correct Answers -Correct. The method promise.then() is used to associate further action with a promise that becomes settled. const p1 = new Promise((resolve, reject) => { setTimeout(() => { resolve('P1 Resolved'); }, 1500); }); const p2 = (data) => new Promise((resolve, reject) => { setTimeout(() => resolve('$ {data}, P2 Resolved'), 1500, data); }); Would the following correctly execute the code? p1().then(function() { p2().then(function(result) { return result; }); }); (Trailhead Question) - Correct Answers -Incorrect. The syntax is wrong for calling p and p2. D as const p1 = new Promise((resolve, reject) => { setTimeout(() => { resolve('P1 Resolved'); }, 1500); }); const p2 = (data) => new Promise((resolve, reject) => { setTimeout(() => resolve('$ {data}, P2 Resolved'), 1500, data); }); (Trailhead Question) Would the following correctly execute the code? async function getResult() { const data = p1; const result = p2(data); } await getResult(); - Correct Answers -Incorrect. The await is outside the function calling the data.
When is await express used outside of the async expression? (Trailhead Question) - Correct Answers -Never async function example { await... } The promise object returned by the new Promise constructor has internal properties. What are they? (Trailhead Question) - Correct Answers -state โ initially "pending", then changes to either "fulfilled" when resolve is called or "rejected" when reject is called. result โ initially undefined, then changes to value when resolve(value) called or error when reject(error) is called. Here is the package.json for the bar.awesome module: {"name": "bar.awesome","version": "1.3.5","peerDependencies": { "baz": "5.x" }} A particular project has the package.json definition below. {"name": "UC Project Extra","version": "0.0.5","dependencies": { "bar.awesome": "1.3.5", "baz": "6.0.0" }} What happens when a developer executes npm install? (Trailhead Question) - Correct Answers -There is a mismatch on the baz dependency that causes the warning. The bar versions are compatible, but the baz versions are not. bar does have a dependency on baz Refer to the code below: 01 const https = require('https'); 02 const server = https.createServer((req, res) => { 03 // code goes here 04 let reqData = JSON.parse(chunk); 05 console.log(reqData); }); res.end('OK'); }); server.listen(8000); Which code does the developer need to add to line 03 to receive incoming request data? A. req.on('data', (chunk) => { B. req.get((chunk) => { C. req.data((chunk) => - Correct Answers -req.on('data', (chunk) => { Correct. The chunk argument is passed in for JSON.parse to use. B req.get((chunk) => { Incorrect. The get method is used with http requests. C req.data((chunk) => { Incorrect. Data is what is getting passed in, not a method. D req.on('get', (chunk) => { Incorrect. The get argument is not passed in so can not be used this way. Which statement sorts the following number array so it is in ascending order? const arr = [7, 3, 400, 10]; (Trailhead)
To display all properties of an object, debug code finish the following for statement. for (_______________________________) { console.log(${i} -> ${connections[i]}); - Correct Answers -for (let i in connections) {