Refutable matching and default values

# Axel Rauschmayer (13 years ago)

harmony:refutable_matching

Question: Does a

Pattern "=" AssignmentExpression

make sense without a prefixed question mark? For example, what would the result of the following statement be?

let {a: x = 1} = {};

Thanks!

Axel

# Andreas Rossberg (13 years ago)

On 28 February 2013 04:06, Axel Rauschmayer <axel at rauschma.de> wrote:

harmony:refutable_matching

Question: Does a

Pattern "=" AssignmentExpression

make sense without a prefixed question mark? For example, what would the result of the following statement be?

let {a: x = 1} = {};

Yes, see the runtime semantics: if x is set to undefined. For example:

let {a: x = 1} = {a: undefined} print(x) // 1

Not saying that this is a particularly useful corner case, but it is in line with the semantics for function default arguments (which should be a special case of pattern matching).