-2

The ECMAScript specification for "abstract equality comparison" (==) has changed between the 6.0 and 9.0 versions, adding an ! character in front of the ToNumber calls in some of the components of the comparison. Can someone tell me why ECMAScript has added this to the spec? It's so confusing.

Here's the version of the spec from 6.0: 6.0 And here's how the spec has changed in 9.0: 9.0 What motivated this change? What does it mean?

Luke Taylor
  • 8,631
  • 8
  • 54
  • 92

1 Answers1

2

See Notational Conventions, specifically ReturnIfAbrupt Shorthands:

Similarly, prefix ! is used to indicate that the following invocation of an abstract or syntax-directed operation will never return an abrupt completion and that the resulting Completion Record's [[Value]] field should be used in place of the return value of the operation. For example, the step:

  1. Let val be ! OperationName().

is equivalent to the following steps:

  1. Let val be OperationName().
  2. Assert: val is never an abrupt completion.
  3. If val is a Completion Record, set val to val.[[Value]].

Syntax-directed operations for runtime semantics make use of this shorthand by placing ! or ? before the invocation of the operation:

  1. Perform ! SyntaxDirectedOperation of NonTerminal.
str
  • 42,689
  • 17
  • 109
  • 127