Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

What happens when you call a function with missing arguments?

Do you know what will be the output of this code?

JavaScript
function add(a, b) {
  return a + b;
}

console.log(add(1));
Show answer and explanation

The answer is NaN.

JavaScript doesn’t check the number of arguments. b is undefined, and 1 + undefined is NaN. A default like b = 0 avoids this.

Take the full quiz Next question →

More Basics questions

  1. How do closures create private variables in JavaScript?
  2. How do you write a once() function with a closure?
  3. Can you call a function before it is declared in JavaScript?
  4. Why can't you call a function expression before it's defined?
  5. Can you change this on a bound function with call()?

Related topics