0
function addNums(num1 = 1, num2 = 2) {
  console.log(num1 + num2);
}
console.log(addNums());

This code results in an output of:
3
undefined

Where is the undefined coming from?

  • 4
    Your `addNums` has no `return` statement, which means it implicitly returns `undefinedd` so you log *that* from `console.log(addNums())` – VLAZ Aug 27 '20 at 18:36
  • Remove the last console.log(addNums()) because it will print the return value of the function (the functions return undefined by default) – Nick Aug 27 '20 at 18:51
  • Long story short, you have 2x `console.log()` in your code, so it will log two values. – Ivar Aug 27 '20 at 19:06

1 Answers1

1

addNums does not return any explicit values, so is implicitly returning undefined, which is being printed on the 2nd console.log statement.

Matt Taylor
  • 11
  • 1
  • 2