Salesforce Certified JavaScript Developer Practice Questions

Salesforce Certified JavaScript Developer exam preparation

Salesforce Certified JavaScript Developer practice questions in English: 180 questions with explanations. The mock exam has 60 questions and 105 minutes.

Salesforce Certified JavaScript Developer free question 9 / 10 · Domain 6: Server Side JavaScript

On a POSIX system, a developer resolves a list of path segments. path.resolve('/foo', '/bar', 'baz'); What does this call return?

  1. /foo/baz, because the last absolute segment is replaced by the first one
  2. /foo/bar/baz, because the segments are appended to the previous one
  3. baz, because the last segment is the file name and earlier segments are ignored
  4. /bar/baz, because processing from right to left stops at /bar
Show the answer and explanation

Answer: D

Why this is correct
path.resolve processes the sequence from right to left, prepending each earlier segment until an absolute path is constructed. baz is not absolute, but /bar + / + baz is, so the result is /bar/baz and /foo is never used.

Why the other options are wrong
"/foo/bar/baz, because the segments are appended to the previous one" … path.resolve processes the segments from right to left and stops once an absolute path is constructed, so /foo is not used.
"/foo/baz, because the last absolute segment is replaced by the first one" … The segments are processed from right to left, so the later absolute path /bar is the one that is kept, followed by baz.
"baz, because the last segment is the file name and earlier segments are ignored" … path.resolve returns an absolute path. Since baz is not absolute, it is prepended with /bar.

Key points
A later absolute segment discards everything before it. path.join, by contrast, only concatenates and normalizes.

Go to the Salesforce Certified JavaScript Developer practice app (10 free questions; purchase unlocks all questions)

See the full practice set