this is not related with es2015 default parameter value since it's use is to assign default value to function parameters.
function parameters (in your case x) acts as local variables to that particular function automatically. so variable x was already declared inside that function.
hence at the time of function call like foo(7) you are just assigning the value 7 to variable x (which is already declared inside function).
if you want to change the value of x inside then you can just use like below
function foo(x=2) {
x=5;
console.log(x); \\ x will be 5
}
even you are using var keyword to re-declare same variable name (here x), it won't re-declare actually (since it was declared already).
to understand better try like below
function foo(x=2) {
var x;
console.log(x); \\ you may expect x to be undefined here but x will be 2 if you call like foo() or x will be 5 if you call like foo(5)
}
summary:
var keyword don't throw any error even you are try to re-declare same variable name as explained above.
but let keyword will throw error when you are trying to re-declare the same variable to avoid such confusions you are facing now.
hope this detailed explanation helps you.