Docsity

300-question practice exam for the Salesforce JavaScript Developer I certification.pdf, Exams of Javascript programming

Toggle sidebar
bg1
300-question practice exam for the Salesforce
JavaScript Developer I certification
Domain 1: Variables, Types, and Collections (Q1–Q69)
1. What does `typeof null` return? (Authentic)
A. `"null"`
B. `"object"`
C. `"undefined"`
D. `"number"`
Answer: B
Rationale: `typeof null` returns `"object"`, a long-standing quirk of JavaScript. To check for `null`,
use strict equality (`value === null`).
2. What does `typeof []` return? (Authentic)
A. `"array"`
B. `"object"`
C. `"list"`
D. `"undefined"`
Answer: B
Rationale: Arrays are objects in JavaScript, so `typeof []` is `"object"`. Use `Array.isArray()` to
reliably check for arrays.
3. What does `1 + '2'` evaluate to? (Authentic)
A. `3`
B. `'12'`
C. `12`
D. `NaN`
Answer: B
Rationale: With `+`, if either operand is a string, JavaScript performs string concatenation. `1 +
'2'` produces the string `"12"`.
4. What does `'3' - 1` evaluate to? (Authentic)
A. `'2'`
B. `2`
C. `NaN`
D. `'31'`
Answer: B
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28

Partial preview of the text

Download 300-question practice exam for the Salesforce JavaScript Developer I certification.pdf and more Exams Javascript programming in PDF only on Docsity!

300-question practice exam for the Salesforce

JavaScript Developer I certification

Domain 1: Variables, Types, and Collections (Q1–Q69)

  1. What does typeof null return? (Authentic) A. "null" B. "object" C. "undefined" D. "number"

Answer: B Rationale: typeof null returns "object", a long-standing quirk of JavaScript. To check for null, use strict equality (value === null).

  1. What does typeof [] return? (Authentic) A. "array" B. "object" C. "list" D. "undefined"

Answer: B Rationale: Arrays are objects in JavaScript, so typeof [] is "object". Use Array.isArray() to reliably check for arrays.

  1. What does 1 + '2' evaluate to? (Authentic) A. 3 B. '12' C. 12 D. NaN

Answer: B Rationale: With +, if either operand is a string, JavaScript performs string concatenation. 1 + '2' produces the string "12".

  1. What does '3' - 1 evaluate to? (Authentic) A. '2' B. 2 C. NaN D. '31'

Answer: B

Rationale: The - operator performs numeric subtraction, coercing the string '3' to the number 3. The result is 2.

  1. Which of the following values are falsy? (Choose three.) (Authentic) A. 0 B. '0' C. '' D. [] E. NaN

Answer: A, C, E Rationale: The falsy values in JavaScript are false, 0, -0, 0n, "", null, undefined, and NaN. The string '0' and the empty array [] are truthy.

  1. A developer needs a new array containing only the names of active accounts, without mutating the original array. Which line achieves this? (Authentic) A. accounts.forEach(a => a.active && a.name) B. accounts.filter(a => a.active).map(a => a.name) C. accounts.splice(1, 1) D. accounts.map(a => a.active? a.name : null)

Answer: B Rationale: filter returns a new array of items that pass the test, and map transforms each item. forEach returns undefined; splice mutates the original array; the map option leaves null entries.

  1. What does JSON.stringify do with properties whose value is undefined? (Authentic) A. Includes them as null B. Omits them from the output C. Throws an error D. Converts them to "undefined"

Answer: B Rationale: JSON.stringify omits properties with undefined values from the resulting JSON string.

  1. What does JSON.parse return when given a valid JSON string? A. A string B. A JavaScript object or value C. undefined D. null

Answer: B

C. undefined D. 0

Answer: A Rationale: The string '0' is non-empty and therefore truthy. Only the empty string '' is falsy among strings.

  1. Which method adds one or more elements to the end of an array and returns the new length? A. push() B. pop() C. shift() D. unshift()

Answer: A Rationale: push() appends elements to the end of an array and returns the new length.

  1. Which method removes the last element from an array? A. pop() B. push() C. shift() D. splice()

Answer: A Rationale: pop() removes and returns the last element of an array.

  1. Which method creates a new array with all elements that pass a test? A. map() B. filter() C. reduce() D. forEach()

Answer: B Rationale: filter() returns a new array containing only elements for which the callback returns true.

  1. Which method executes a reducer function on each element, resulting in a single output value? A. map() B. filter() C. reduce() D. forEach()

Answer: C

Rationale: reduce() applies a reducer function across an array to produce a single accumulated value.

  1. What is the difference between let and var in terms of scope? A. let is function-scoped; var is block-scoped. B. let is block-scoped; var is function-scoped. C. Both are block-scoped. D. Both are function-scoped.

Answer: B Rationale: let and const are block-scoped, meaning they are confined to the nearest enclosing block. var is function-scoped.

  1. What is hoisting in JavaScript? A. Moving declarations to the top of their scope B. Moving functions to the bottom of the file C. Deleting variables after use D. Converting types automatically

Answer: A Rationale: Hoisting is JavaScript's behavior of moving declarations (not initializations) to the top of their containing scope during compilation.

  1. What does NaN === NaN evaluate to? A. true B. false C. undefined D. Throws an error

Answer: B Rationale: NaN is not equal to itself. Use Number.isNaN() to test for NaN.

  1. Which of the following is a valid way to create a Map? A. new Map() B. Map() C. new map() D. Map.create()

Answer: A Rationale: Map is a constructor and must be instantiated with new Map().

  1. What is the primary difference between a Map and a plain object? A. Map keys can be any type; object keys are strings or symbols. B. Map keys must be strings.
  1. What is the result of [] + {}? A. '[object Object]' B. '{}' C. NaN D. undefined

Answer: A Rationale: The array is coerced to '' and the object to '[object Object]', producing the string '[object Object]'.

  1. What is the result of {} + []? A. '[object Object]' B. 0 C. '' D. NaN

Answer: B Rationale: At the start of a statement, {} is parsed as a block, and +[] coerces the array to 0. The result is 0.

  1. Which operator performs strict equality without type coercion? A. == B. === C. = D. !=

Answer: B Rationale: === compares both value and type without coercion. == performs type coercion.

  1. What does null == undefined evaluate to? A. true B. false C. undefined D. Throws an error

Answer: A Rationale: With loose equality (==), null and undefined are considered equal. With strict equality (===), they are not.

  1. What does null === undefined evaluate to? A. true B. false C. undefined

D. Throws an error

Answer: B Rationale: Strict equality requires both value and type to match. null and undefined are different types.

  1. Which method converts a string to an integer? A. parseInt() B. parseFloat() C. Number() D. String()

Answer: A Rationale: parseInt() parses a string and returns an integer. parseFloat() returns a floating- point number.

  1. What does parseInt('08') return in modern JavaScript? A. 0 B. 8 C. NaN D. '08'

Answer: B Rationale: Modern JavaScript treats strings starting with 0 as decimal unless a radix is specified. parseInt('08') returns 8.

  1. What does Number('') return? A. 0 B. NaN C. undefined D. ''

Answer: A Rationale: Number('') converts the empty string to 0.

  1. What does Number('abc') return? A. 0 B. NaN C. undefined D. 'abc'

Answer: B Rationale: Number() returns NaN when the string cannot be converted to a valid number.

Rationale: join() concatenates array elements into a single string, separated by a specified delimiter.

  1. What does new Date().getTime() return? A. The current date as a string B. The number of milliseconds since January 1, 1970 C. The current year D. The time zone offset

Answer: B Rationale: getTime() returns the numeric value of the date in milliseconds since the Unix epoch.

  1. Which method returns the month (0–11) of a Date object? A. getMonth() B. getDate() C. getDay() D. getYear()

Answer: A Rationale: getMonth() returns the month as a zero-based index (0 = January, 11 = December).

  1. What does [1, 2, 3].length return? A. 2 B. 3 C. 4 D. undefined

Answer: B Rationale: The length property returns the number of elements in the array.

  1. What does 'hello'.length return? A. 4 B. 5 C. 6 D. undefined

Answer: B Rationale: The length property returns the number of characters in the string.

  1. Which method returns a shallow copy of a portion of an array? A. slice() B. splice() C. concat()

D. join()

Answer: A Rationale: slice() returns a shallow copy of a portion of an array into a new array without modifying the original.

  1. Which method changes the contents of an array by removing or replacing existing elements? A. slice() B. splice() C. concat() D. map()

Answer: B Rationale: splice() mutates the original array by removing, replacing, or adding elements.

  1. What does [1, 2, 3].indexOf(2) return? A. 0 B. 1 C. 2 D. -1

Answer: B Rationale: indexOf() returns the first index at which the specified element is found, or -1 if not present.

  1. What does [1, 2, 3].includes(4) return? A. true B. false C. -1 D. undefined

Answer: B Rationale: includes() checks whether an array contains a specified element and returns a boolean.

  1. Which of the following is a correct way to destructure an array? A. const [a, b] = [1, 2]; B. const {a, b} = [1, 2]; C. const a, b = [1, 2]; D. const [a, b] = {1, 2};

Answer: A Rationale: Array destructuring uses square brackets: const [a, b] = [1, 2];.

Rationale: const prevents reassignment of the binding, but the object's properties can still be mutated unless the object is frozen with Object.freeze().

  1. What does Object.freeze() do? A. Prevents any changes to an object B. Creates a deep copy C. Converts an object to a string D. Deletes all properties

Answer: A Rationale: Object.freeze() makes an object immutable, preventing addition, deletion, or modification of properties.

  1. Which method returns an array of an object's own enumerable property names? A. Object.values() B. Object.keys() C. Object.entries() D. Object.getOwnPropertyNames()

Answer: B Rationale: Object.keys() returns an array of the object's own enumerable property names.

  1. Which method returns an array of [key, value] pairs? A. Object.keys() B. Object.values() C. Object.entries() D. Object.assign()

Answer: C Rationale: Object.entries() returns an array of [key, value] pairs for the object's own enumerable properties.

  1. What is the output of console.log(0.1 + 0.2 === 0.3)? A. true B. false C. undefined D. Throws an error

Answer: B Rationale: Due to floating-point precision, 0.1 + 0.2 is not exactly 0.3, so the strict equality comparison returns false.

  1. What is the value of 2 3? A. 5

B. 6

C. 8

D. 9

Answer: C Rationale: The exponentiation operator `` raises the first operand to the power of the second: 3 = 8.

  1. Which operator returns the remainder of a division? A. % B. / C. // D. \

Answer: A Rationale: The modulo operator % returns the remainder of a division operation.

  1. What does 10 % 3 return? A. 3 B. 1 C. 0 D. 3.33

Answer: B Rationale: 10 % 3 returns the remainder 1.

  1. Which method checks if a value is NaN? A. isNaN() B. Number.isNaN() C. typeof value === 'NaN' D. value === NaN

Answer: B Rationale: Number.isNaN() reliably checks whether a value is NaN without coercing the argument. Global isNaN() coerces the argument first.

  1. What does Number.isNaN('abc') return? A. true B. false C. NaN D. undefined

Answer: B

B. To store large numbers C. To represent null D. To convert strings to numbers

Answer: A Rationale: Symbols are primarily used as unique property keys that avoid name collisions.

  1. What does [1, 2, 3].reverse() return? A. A new reversed array B. The original array reversed in place C. A string D. undefined

Answer: B Rationale: reverse() mutates the original array by reversing its elements in place and returns the same array.

Domain 2: Objects, Functions, and Classes (Q70–Q144)

  1. What is the output of the following code? (Authentic)
let x = 5; function test() { console.log(x); let x = 10; } test();

A. 5 B. 10 C. undefined D. ReferenceError

Answer: D Rationale: The let x inside test() creates a temporal dead zone. Accessing x before its declaration within the same scope throws a ReferenceError.

  1. What is the output of the following code? (Authentic)
var x = 5; function test() { console.log(x); var x = 10; } test();

A. 5 B. 10 C. undefined D. ReferenceError

Answer: C Rationale: var x inside test() is hoisted to the top of the function, so console.log(x) prints undefined before the local assignment.

  1. What is a closure? A. A function that has access to variables from its outer lexical scope even after the outer function has returned B. A function that takes another function as an argument C. A function that returns a promise D. A function that is immediately invoked

Answer: A Rationale: A closure is a function bundled with its lexical environment, allowing it to access outer-scope variables even after the outer function has finished executing.

  1. What does this refer to in a regular function called as a standalone function in non-strict mode? A. The global object B. undefined C. The function itself D. null

Answer: A Rationale: In non-strict mode, this in a standalone function call refers to the global object (e.g., window in browsers). In strict mode, it is undefined.

  1. What does this refer to in an arrow function? A. The object that calls the function B. The lexical this of the enclosing scope C. undefined D. The global object always

Answer: B Rationale: Arrow functions do not have their own this; they inherit this from the enclosing lexical scope.

Answer: A Rationale: new creates a new empty object, links it to the constructor's prototype, binds this to the new object, and executes the constructor.

  1. What is a prototype in JavaScript? A. A template object from which other objects inherit properties B. A class in Java C. A type of function D. A built-in variable

Answer: A Rationale: Every JavaScript object has a prototype, which is an object from which it inherits properties and methods.

  1. What does Object.create(proto) do? A. Creates a new object with the specified prototype object B. Creates a copy of proto C. Deletes proto D. Converts proto to a class

Answer: A Rationale: Object.create() creates a new object using the specified object as its prototype.

  1. How do you define a class in ES6? A. class Person {} B. function Person() {} C. object Person {} D. new class Person

Answer: A Rationale: ES6 introduced the class keyword for defining classes with a cleaner syntax.

  1. What is the purpose of the constructor method in a class? A. To initialize new instances of the class B. To destroy instances C. To inherit from another class D. To create static methods

Answer: A Rationale: The constructor method is called automatically when a new instance is created and is used to initialize the object.

  1. How do you inherit from a class in ES6? A. class Child extends Parent {}

B. class Child inherits Parent {} C. class Child : Parent {} D. class Child = Parent {}

Answer: A Rationale: The extends keyword is used to create a subclass that inherits from a parent class.

  1. What does super() do in a subclass constructor? A. Calls the parent class constructor B. Creates a new object C. Deletes the parent class D. Returns a promise

Answer: A Rationale: super() invokes the constructor of the parent class and must be called before using this in a subclass constructor.

  1. What is a static method in a class? A. A method called on the class itself, not on instances B. A method that cannot be overridden C. A method that is always private D. A method that returns a promise

Answer: A Rationale: Static methods are defined with the static keyword and are called on the class itself, not on instances.

  1. What is the output of the following code?
class A { constructor() { this.x = 1; } getX() { return this.x; } } class B extends A { constructor() { super(); this.x = 2; } } console.log(new B().getX());

A. 1 B. 2 C. undefined D. Throws an error

Answer: B