1 of 4

Daniel Ehrenberg

Bloomberg

September 2023

TC39 Tokyo

2 of 4

Motivation for proposal

  • There are many numeric quantities which aren't literally numbers
    • CSSOM
    • Decimals (in existing libraries)
    • Quantities connected with units of measure (important to reduce bugs)
  • It'd be good to encourage their typed usage
    • Clean syntax makes use lower friction and maybe more likely to use than buggy Numbers
  • "Explain" BigInt literals (and possible future built-in decimal literals)

3 of 4

One idea for syntax and semantics

Semantics similar to tagged templates; no relationship to operator overloading

Polyfill for the hypothetical CSS px literal suffix:

function pxSuffix({number}) {

return CSS.px(number)

}

with suffix px = pxSuffix;

3px;

The last line desugars into:

pxSuffix(Object.freeze({ number: 3, string: "3" }));

4 of 4

Motivation for withdrawing

  • Operator overloading was proposed for withdrawal
    • If that didn't get consensus before this presentation, then consider not withdrawing
  • Developers expect that suffixes imply operator overloading
  • Syllogism result: Custom numeric literals violate developer expectations

  • Consensus on withdrawing?