What is the output of the following? “`js function foo(a, b = a * 2, c = a + b) { return [a, b, c]; } console.log(foo(3)); “`

JavaScript Professional Medium

JavaScript Professional — Medium

What is the output of the following? “`js function foo(a, b = a * 2, c = a + b) { return [a, b, c]; } console.log(foo(3)); “`

Key points

  • Default parameter values are evaluated at runtime
  • Default values can be expressions
  • Parameters without default values must be defined before those with default values

Ready to go further?

Related questions