MCD-LEVEL-1 practice question 13 of 30

Correct answer is {customerID}. Reference: https://docs.mulesoft.com/http-connector/1.5/http-listener-ref A function named toUpper needs to be defined that accepts a string named userName and returns the string in uppercase. What is the correct DW code to define the toUpper function?

Full set: 235 questions
Answer options
A: var toUpper(userName) -> upper(userName)
B: fun toUpper(userName) = upper(userName) Correct answer
C: fun toUpper(userName) -> upper(userName)
D: var toUpper(userName) = upper(userName)
Correct Answer:
B. fun toUpper(userName) = upper(userName)
Explanation

In DataWeave 2.0, custom functions are declared using the fun keyword. The correct syntax requires the fun keyword, followed by the function name, its parameters enclosed in parentheses, an equals sign (=), and finally the expression body. Therefore, fun toUpper(userName) = upper(userName) is the syntactically correct way to define a function that accepts a string and converts it to uppercase.

Why Incorrect

A: The var keyword is used to declare variables, not functions, and the -> operator is used for lambda expressions, not standard function definitions. C: The -> operator is incorrect for standard function definitions; an equals sign (=) must be used to assign the expression body to the function. D: The var keyword is strictly used to declare variables, whereas the fun keyword is required to declare custom functions.

References

MuleSoft Official Documentation: DataWeave Language -> DataWeave Scripts -> "Define Functions" (Section: Using the fun keyword).

Scroll to Top