If a JavaScript function does not return a value, what is returned by default?

Study for the CodeHS AP Computer Science Principles (CSP) Exam. Prepare with flashcards and multiple choice questions, each question comes with hints and explanations. Get ready for success!

Multiple Choice

If a JavaScript function does not return a value, what is returned by default?

Explanation:
In JavaScript, a function that doesn’t return anything finishes with an implicit return of undefined. Undefined is a special value that signals the absence of a value. It’s different from null (explicitly “no value”), 0 (a number), or false (a boolean). For example, function f() { console.log('hi'); } var result = f(); // result is undefined. typeof result is "undefined". Because there was no return statement, the function yields undefined by default.

In JavaScript, a function that doesn’t return anything finishes with an implicit return of undefined. Undefined is a special value that signals the absence of a value. It’s different from null (explicitly “no value”), 0 (a number), or false (a boolean). For example, function f() { console.log('hi'); } var result = f(); // result is undefined. typeof result is "undefined". Because there was no return statement, the function yields undefined by default.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy