1. // 参数的默认值
    2. function save(filename = throw new TypeError("Argument required")) {
    3. }
    4. // 箭头函数的返回值
    5. lint(ast, {
    6. with: () => throw new Error("avoid using 'with' statements.")
    7. });
    8. function getEncoder(encoding) {
    9. const encoder = encoding === "utf8" ?
    10. new UTF8Encoder() :
    11. encoding === "utf16le" ?
    12. new UTF16Encoder(false) :
    13. encoding === "utf16be" ?
    14. new UTF16Encoder(true) :
    15. throw new Error("Unsupported encoding");
    16. }
    17. // 逻辑表达式
    18. class Product {
    19. return this._id;
    20. }
    21. set id(value) {
    22. this._id = value || throw new Error("Invalid value");
    23. }
    24. }