A new expression is expression cherry picked from the recent discussion about pattern matching.
Syntax
RelationalExpression `is` MatchPattern
This syntax has the same priority as instanceof and in expression.
Semantics
Check if the LHS expression match the RHS pattern, returns a boolean.
It does not introduce new bindings in the current scope.
Note
The MatchPattern and its semantics is unmodified, therefore it have some unintuitive behaviors like:
if (x is y) {
// always runs, because y is a always success match.
}
if (z is { type }) {
type // ReferenceError. is expression does not introduce new bindings.
}
is
expressionA new expression
is expression
cherry picked from the recent discussion about pattern matching.Syntax
This syntax has the same priority as
instanceof
andin
expression.Semantics
Check if the LHS expression match the RHS pattern, returns a boolean.
It does not introduce new bindings in the current scope.
Note
The
MatchPattern
and its semantics is unmodified, therefore it have some unintuitive behaviors like:Syntax bikeshedding
Maybe
expr matches pattern
?