Javascript - What is the output: default parameter scope?

Question

What is the output of the following code?

var getPrice = function(count = price, price = 5) { 
        console.log(count + ", " + price); 
} 

getPrice(); 


Click to view the answer

ReferenceError: price is not defined

Note

You can think of the function declaration and arguments like a scope.

The parameters of a function declaration are in their own scope between the parentheses (...).

Therefore, in the above example a reference error occurs when you try to use a parameter before it is declared.

Related Quiz