What is the output of the function sayHi when executed as follows: function sayHi() { return (() => 0)(); } console.log(typeof sayHi());?

Prepare for the Salesforce JavaScript Developer Exam. Utilize comprehensive quizzes, flashcards, and multiple choice questions with hints and explanations. Boost your exam readiness!

The function sayHi is defined to return the result of an immediately invoked arrow function, which simply returns the value 0. When the arrow function is executed, it evaluates to 0.

In JavaScript, the typeof operator is used to determine the type of a value. When sayHi is called, it results in 0, a number. Thus, when typeof sayHi() is evaluated, it checks the type of this returned value, which is 0. The typeof 0 gives the string "number".

This is why the output of console.log(typeof sayHi()); results in the string "number". Hence, the correct answer is that the output of the function when executed in this manner is "number".

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy