函数

一般来说,函数是子程序,可以被 called by code external (or internal in the case of recursion) to the function. Like the program itself, a function is composed of a sequence of statements called the function body . Values can be passed to a function, and the function will return a value.

In JavaScript, functions are first-class objects, because they can have properties and methods just like any other object. What distinguishes them from other objects is that functions can be called. In brief, they are Function 对象。

更多范例和解释,另请参阅 JavaScript 函数指南 .

描述

JavaScript 中的每个函数都是 Function 对象。见 Function 了解有关特性和方法的信息为 Function 对象。

To return a value other than the default, a function must have a return statement that specifies the value to return. A function without a return statement will return a default value. In the case of a 构造函数 被调用采用 new 关键词,默认值是它的值源于 this 参数。对于所有其它函数,默认返回值是 undefined .

函数调用的参数是函数的 arguments 。自变量被传递给函数 by value . If the function changes the value of an argument, this change is not reflected globally or in the calling function. However, object references are values, too, and they are special: if the function changes the referred object's properties, that change is visible outside the function, as shown in the following example:

/* Declare the function 'myFunc' */
function myFunc(theObject) {
  theObject.brand = "Toyota";
}
/*
 * Declare variable 'mycar';
 * create and initialize a new Object;
 * assign reference to it to 'mycar'
 */
var mycar = {
  brand: "Honda",
  model: "Accord",
  year: 1998
};
/* Logs 'Honda' */
console.log(mycar.brand);
/* Pass object reference to the function */
myFunc(mycar);
/*
 * Logs 'Toyota' as the value of the 'brand' property
 * of the object, as changed to by the function.
 */
console.log(mycar.brand);
					

this keyword does not refer to the currently executing function, so you must refer to Function 对象按名称,即使在函数本体内。

定义函数

有几种定义函数的方式:

函数声明 ( function 语句)

声明函数的特殊句法 (见 function statement 了解细节):

function name([param[, param[, ... param]]]) {
   statements
}
					
name
函数名称。
param
要被传递给函数的自变量名称。
statements
由函数本体组成的语句。

函数表达式 ( function 表达式)

A function expression is similar to and has the same syntax as a function declaration (see 函数表达式 for details). A function expression may be a part of a larger expression. One can define "named" function expressions (where the name of the expression might be used in the call stack for example) or "anonymous" function expressions. Function expressions are not hoisted onto the beginning of the scope, therefore they cannot be used before they appear in the code.

function [name]([param[, param[, ... param]]]) {
   statements
}
					
name
函数名称。可以省略,在这种情况下,函数变为匿名函数。
param
要被传递给函数的自变量名称。
statements
由函数本体组成的语句。

这里是范例 anonymous 函数表达式 ( name 未使用):

var myFunction = function() {
    statements
}
					

It is also possible to provide a name inside the definition in order to create a named 函数表达式:

var myFunction = function namedFunction(){
    statements
}
					

One of the benefits of creating a named function expression is that in case we encountered an error, the stack trace will contain the name of the function, making it easier to find the origin of the error.

As we can see, both examples do not start with the function keyword. Statements involving functions which do not start with function are function expressions.

When functions are used only once, a common pattern is an IIFE (Immediately Invoked Function Expression) .

(function() {
    statements
})();
					

IIFE are function expressions that are invoked as soon as the function is declared.

生成器函数声明 ( function* 语句)

There is a special syntax for generator function declarations (see function* 语句 了解细节):

function* name([param[, param[, ... param]]]) {
   statements
}
					
name
函数名称。
param
要被传递给函数的自变量名称。
statements
由函数本体组成的语句。

生成器函数表达式 ( function* 表达式)

A generator function expression is similar to and has the same syntax as a generator function declaration (see function* 表达式 了解细节):

function* [name]([param[, param[, ... param]]]) {
   statements
}
					
name
函数名称。可以省略,在这种情况下,函数变为匿名函数。
param
要被传递给函数的自变量名称。
statements
由函数本体组成的语句。

The arrow function expression (=>)

An arrow function expression has a shorter syntax and lexically binds its this 值 (见 箭头函数 了解细节):

([param[, param]]) => {
   statements
}
param => expression
					
param
自变量的名称。零个自变量需要指示采用 () .  For only one argument, the parentheses are not required. (like foo => 1 )
statements or expression
Multiple statements need to be enclosed in brackets. A single expression requires no brackets. The expression is also the implicit return value of the function.

Function 构造函数

注意: 使用 Function 构造函数去创建函数不推荐,因为它需要把函数本体作为字符串,可能阻止某些 JS 引擎优化且还会导致其它问题。

如所有其它对象, Function 对象可以被创建使用 new 运算符:

new Function (arg1, arg2, ... argN, functionBody)
					
arg1, arg2, ... arg N
Zero or more names to be used by the function as formal parameters. Each must be a proper JavaScript identifier.
functionBody
A string containing the JavaScript statements comprising the function body.

援引 Function 构造函数作为函数 (不使用 new 运算符) 有相同效果若把它作为构造函数进行援引。

GeneratorFunction 构造函数

注意: GeneratorFunction is not a global object, but could be obtained from generator function instance (see GeneratorFunction for more detail).

注意: 使用 GeneratorFunction 构造函数去创建函数不推荐,因为它需要把函数本体作为字符串,可能阻止某些 JS 引擎优化且还会导致其它问题。

如所有其它对象, GeneratorFunction 对象可以被创建使用 new 运算符:

new GeneratorFunction (arg1, arg2, ... argN, functionBody)
					
arg1, arg2, ... arg N
Zero or more names to be used by the function as formal argument names. Each must be a string that conforms to the rules for a valid JavaScript identifier or a list of such strings separated with a comma; for example " x ", " theValue ", or " a,b ".
functionBody
A string containing the JavaScript statements comprising the function definition.

援引 GeneratorFunction 构造函数作为函数 (不使用 new 运算符) 有相同效果若把它作为构造函数进行援引。

函数参数

默认参数

默认函数参数允许采用默认值初始化形式参数若没有值或 undefined 被传递。了解更多细节,见 默认参数 .

其余参数

The rest parameter syntax allows representing an indefinite number of arguments as an array. For more details, see rest parameters .

arguments object

You can refer to a function's arguments within the function by using the arguments 对象。见 arguments .

定义方法函数

Getter 和 Setter 函数

You can define getters (accessor methods) and setters (mutator methods) on any standard built-in object or user-defined object that supports the addition of new properties. The syntax for defining getters and setters uses the object literal syntax.

get

Binds an object property to a function that will be called when that property is looked up.

set
Binds an object property to a function to be called when there is an attempt to set that property.

方法定义语法

Starting with ECMAScript 2015, you are able to define own methods in a shorter syntax, similar to the getters and setters. See method definitions 了解更多信息。

var obj = {
  foo() {},
  bar() {}
};
					

构造函数 vs 声明 vs 表达式

Compare the following:

A function defined with the Function 构造函数 assigned to the variable multiply:

var multiply = new Function('x', 'y', 'return x * y');
					

A 函数声明 of a function named multiply :

function multiply(x, y) {
   return x * y;
} // there is no semicolon here
					

A 函数表达式 of an anonymous function assigned to the variable multiply:

var multiply = function(x, y) {
   return x * y;
};
					

A 函数表达式 of a function named func_name assigned to the variable multiply:

var multiply = function func_name(x, y) {
   return x * y;
};
					

Differences

All do approximately the same thing, with a few subtle differences:

There is a distinction between the function name and the variable the function is assigned to. The function name cannot be changed, while the variable the function is assigned to can be reassigned. The function name can be used only within the function's body. Attempting to use it outside the function's body results in an error (or undefined if the function name was previously declared via a var statement). For example:

var y = function x() {};
alert(x); // throws an error
					

The function name also appears when the function is serialized via Function 's toString method .

On the other hand, the variable the function is assigned to is limited only by its scope, which is guaranteed to include the scope in which the function is declared.

As the 4th example shows, the function name can be different from the variable the function is assigned to. They have no relation to each other. A function declaration also creates a variable with the same name as the function name. Thus, unlike those defined by function expressions, functions defined by function declarations can be accessed by their name in the scope they were defined in:

A function defined by ' new Function' does not have a function name. However, in the SpiderMonkey JavaScript engine, the serialized form of the function shows as if it has the name "anonymous". For example, alert(new Function()) outputs:

function anonymous() {
}
					

Since the function actually does not have a name, anonymous is not a variable that can be accessed within the function. For example, the following would result in an error:

var foo = new Function("alert(anonymous);");
foo();
					

Unlike functions defined by function expressions or by the Function constructor, a function defined by a function declaration can be used before the function declaration itself. For example:

foo(); // alerts FOO!
function foo() {
   alert('FOO!');
}
					

A function defined by a function expression or by a function declaration inherits the current scope. That is, the function forms a closure. On the other hand, a function defined by a Function constructor does not inherit any scope other than the global scope (which all functions inherit).

/*
 * Declare and initialize a variable 'p' (global)
 * and a function 'myFunc' (to change the scope) inside which
 * declare a varible with same name 'p' (current) and
 * define three functions using three different ways:-
 *     1. function declaration
 *     2. function expression
 *     3. function constructor
 * each of which will log 'p'
 */
var p = 5;
function myFunc() {
    var p = 9;
    function decl() {
        console.log(p);
    }
    var expr = function() {
        console.log(p);
    };
    var cons = new Function('\tconsole.log(p);');
    decl();
    expr();
    cons();
}
myFunc();
/*
 * Logs:-
 * 9  - for 'decl' by function declaration (current scope)
 * 9  - for 'expr' by function expression (current scope)
 * 5  - for 'cons' by Function constructor (global scope)
 */
					

Functions defined by function expressions and function declarations are parsed only once, while those defined by the Function constructor are not. That is, the function body string passed to the Function constructor must be parsed each and every time the constructor is called. Although a function expression creates a closure every time, the function body is not reparsed, so function expressions are still faster than " new Function(...) ". Therefore the Function constructor should generally be avoided whenever possible.

It should be noted, however, that function expressions and function declarations nested within the function generated by parsing a Function constructor 's string aren't parsed repeatedly. For example:

var foo = (new Function("var bar = \'FOO!\';\nreturn(function() {\n\talert(bar);\n});"))();
foo(); // The segment "function() {\n\talert(bar);\n}" of the function body string is not re-parsed.
					

A function declaration is very easily (and often unintentionally) turned into a function expression. A function declaration ceases to be one when it either:

  • becomes part of an expression
  • is no longer a "source element" of a function or the script itself. A "source element" is a non-nested statement in the script or a function body:
var x = 0;               // source element
if (x === 0) {           // source element
   x = 10;               // not a source element
   function boo() {}     // not a source element
}
function foo() {         // source element
   var y = 20;           // source element
   function bar() {}     // source element
   while (y === 10) {    // source element
      function blah() {} // not a source element
      y++;               // not a source element
   }
}
					

范例

// function declaration
function foo() {}
// function expression
(function bar() {})
// function expression
x = function hello() {}
if (x) {
   // function expression
   function world() {}
}
// function declaration
function a() {
   // function declaration
   function b() {}
   if (0) {
      // function expression
      function c() {}
   }
}
					

块级函数

In 严格模式 , starting with ES2015, functions inside blocks are now scoped to that block. Prior to ES2015, block-level functions were forbidden in strict mode.

'use strict';
function f() {
  return 1;
}
{
  function f() {
    return 2;
  }
}
f() === 1; // true
// f() === 2 in non-strict mode
					

非严格代码中的块级函数

In a word: Don't.

In non-strict code, function declarations inside blocks behave strangely. For example:

if (shouldDefineZero) {
   function zero() {     // DANGER: compatibility risk
      console.log("This is zero.");
   }
}
					

ES2015 says that if shouldDefineZero is false, then zero should never be defined, since the block never executes. However, it's a new part of the standard. Historically, this was left unspecified, and some browsers would define zero whether the block executed or not.

In 严格模式 , all browsers that support ES2015 handle this the same way: zero is defined only if shouldDefineZero is true, and only in the scope of the if -block.

A safer way to define functions conditionally is to assign a function expression to a variable:

var zero;
if (shouldDefineZero) {
   zero = function() {
      console.log("This is zero.");
   };
}
					

范例

返回格式化的数字

The following function returns a string containing the formatted representation of a number padded with leading zeros.

// This function returns a string padded with leading zeros
function padZeros(num, totalLen) {
   var numStr = num.toString();             // Initialize return value as string
   var numZeros = totalLen - numStr.length; // Calculate no. of zeros
   for (var i = 1; i <= numZeros; i++) {
      numStr = "0" + numStr;
   }
   return numStr;
}
					

以下语句调用 padZeros 函数。

var result;
result = padZeros(42,4); // returns "0042"
result = padZeros(42,2); // returns "42"
result = padZeros(5,4);  // returns "0005"
					

Determining whether a function exists

You can determine whether a function exists by using the typeof operator. In the following example, a test is performed to determine if the window object has a property called noFunc that is a function. If so, it is used; otherwise, some other action is taken.

 if ('function' === typeof window.noFunc) {
   // use noFunc()
 } else {
   // do something else
 }
					

注意:在 if test, a reference to noFunc is used—there are no brackets "()" after the function name so the actual function is not called.

规范

规范
ECMAScript (ECMA-262)
The definition of 'Function definitions' in that specification.

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
函数 Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs Yes
arguments Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs Yes
箭头函数 Chrome 45 Edge 12 Firefox 22
22
The initial implementation of arrow functions in Firefox made them automatically strict. This has been changed as of Firefox 24. The use of 'use strict'; is now required.
Prior to Firefox 39, a line terminator ( \n ) was incorrectly allowed after arrow function arguments. This has been fixed to conform to the ES2015 specification and code like () \n => {} will now throw a SyntaxError in this and later versions.
IE No Opera 32 Safari 10 WebView Android 45 Chrome Android 45 Firefox Android 22
22
The initial implementation of arrow functions in Firefox made them automatically strict. This has been changed as of Firefox 24. The use of 'use strict'; is now required.
Prior to Firefox 39, a line terminator ( \n ) was incorrectly allowed after arrow function arguments. This has been fixed to conform to the ES2015 specification and code like () \n => {} will now throw a SyntaxError in this and later versions.
Opera Android 32 Safari iOS 10 Samsung Internet Android 5.0 nodejs Yes
块级函数 Chrome 49 Edge 12 Firefox 46 IE 11 Opera 36 Safari 10 WebView Android 49 Chrome Android 49 Firefox Android 46 Opera Android 36 Safari iOS 10 Samsung Internet Android 5.0 nodejs ?
默认参数 Chrome 49 Edge 14 Firefox 15 IE No Opera 36 Safari 10 WebView Android 49 Chrome Android 49 Firefox Android 15 Opera Android 36 Safari iOS 10 Samsung Internet Android 5.0 nodejs 6.0.0
get Chrome 1 Edge 12 Firefox 1.5 IE 9 Opera 9.5 Safari 3 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 14 Safari iOS 1 Samsung Internet Android 1.0 nodejs Yes
方法定义 Chrome 39 Edge 12 Firefox 34 IE No Opera 26 Safari 9 WebView Android 39 Chrome Android 39 Firefox Android 34 Opera Android 26 Safari iOS 9 Samsung Internet Android 4.0 nodejs Yes
其余参数 Chrome 47 Edge 12 Firefox 15 IE No Opera 34 Safari 10 WebView Android 47 Chrome Android 47 Firefox Android 15 Opera Android 34 Safari iOS 10 Samsung Internet Android 5.0 nodejs 6.0.0
6.0.0
4.0.0
Disabled
Disabled From version 4.0.0: this feature is behind the --harmony runtime flag.
set Chrome 1 Edge 12 Firefox 1.5 IE 9 Opera 9.5 Safari 3 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 14 Safari iOS 1 Samsung Internet Android 1.0 nodejs Yes

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
见实现注意事项。
用户必须明确启用此特征。
用户必须明确启用此特征。

另请参阅

Metadata

  1. JavaScript
  2. 教程:
  3. 完整初学者
    1. JavaScript 基础
    2. JavaScript 第一步
    3. JavaScript 构建块
    4. 引入 JavaScript 对象
  4. JavaScript 指南
    1. 介绍
    2. 语法和类型
    3. 控制流程和错误处理
    4. 循环和迭代
    5. 函数
    6. 表达式和运算符
    7. 数字和日期
    8. 文本格式
    9. 正则表达式
    10. Indexed collections
    11. Keyed collections
    12. Working with objects
    13. 对象模型的细节
    14. Using promises
    15. 迭代器和生成器
    16. Meta programming
    17. JavaScript 模块
  5. 中间体
    1. Client-side JavaScript frameworks
    2. 客户端侧 Web API
    3. 重新介绍 JavaScript
    4. JavaScript 数据结构
    5. 相等比较和相同
    6. 闭包
  6. 高级
    1. 继承和原型链
    2. 严格模式
    3. JavaScript 类型数组
    4. 内存管理
    5. 并发模型和事件循环
  7. 参考:
  8. 内置对象
    1. AggregateError
    2. Array
    3. ArrayBuffer
    4. AsyncFunction
    5. Atomics
    6. BigInt
    7. BigInt64Array
    8. BigUint64Array
    9. Boolean
    10. DataView
    11. Date
    12. Error
    13. EvalError
    14. FinalizationRegistry
    15. Float32Array
    16. Float64Array
    17. Function
    18. Generator
    19. GeneratorFunction
    20. Infinity
    21. Int16Array
    22. Int32Array
    23. Int8Array
    24. InternalError
    25. Intl
    26. JSON
    27. Map
    28. Math
    29. NaN
    30. Number
    31. Object
    32. Promise
    33. Proxy
    34. RangeError
    35. ReferenceError
    36. Reflect
    37. RegExp
    38. Set
    39. SharedArrayBuffer
    40. String
    41. Symbol
    42. SyntaxError
    43. TypeError
    44. TypedArray
    45. URIError
    46. Uint16Array
    47. Uint32Array
    48. Uint8Array
    49. Uint8ClampedArray
    50. WeakMap
    51. WeakRef
    52. WeakSet
    53. WebAssembly
    54. decodeURI()
    55. decodeURIComponent()
    56. encodeURI()
    57. encodeURIComponent()
    58. escape()
    59. eval()
    60. globalThis
    61. isFinite()
    62. isNaN()
    63. null
    64. parseFloat()
    65. parseInt()
    66. undefined
    67. unescape()
    68. uneval()
  9. 表达式 & 运算符
    1. Addition (+)
    2. Addition assignment (+=)
    3. Assignment (=)
    4. Bitwise AND (&)
    5. Bitwise AND assignment (&=)
    6. Bitwise NOT (~)
    7. Bitwise OR (|)
    8. Bitwise OR assignment (|=)
    9. Bitwise XOR (^)
    10. Bitwise XOR assignment (^=)
    11. Comma operator (,)
    12. 条件 (三元) 运算符
    13. Decrement (--)
    14. Destructuring assignment
    15. Division (/)
    16. Division assignment (/=)
    17. Equality (==)
    18. Exponentiation (**)
    19. Exponentiation assignment (**=)
    20. Function expression
    21. Greater than (>)
    22. Greater than or equal (>=)
    23. Grouping operator ( )
    24. Increment (++)
    25. Inequality (!=)
    26. Left shift (<<)
    27. Left shift assignment (<<=)
    28. Less than (<)
    29. Less than or equal (<=)
    30. Logical AND (&&)
    31. Logical AND assignment (&&=)
    32. Logical NOT (!)
    33. Logical OR (||)
    34. Logical OR assignment (||=)
    35. Logical nullish assignment (??=)
    36. Multiplication (*)
    37. Multiplication assignment (*=)
    38. Nullish coalescing operator (??)
    39. Object initializer
    40. 运算符优先级
    41. Optional chaining (?.)
    42. Pipeline operator (|>)
    43. 特性访问器
    44. Remainder (%)
    45. Remainder assignment (%=)
    46. Right shift (>>)
    47. Right shift assignment (>>=)
    48. Spread syntax (...)
    49. Strict equality (===)
    50. Strict inequality (!==)
    51. Subtraction (-)
    52. Subtraction assignment (-=)
    53. Unary negation (-)
    54. Unary plus (+)
    55. Unsigned right shift (>>>)
    56. Unsigned right shift assignment (>>>=)
    57. 异步函数表达式
    58. await
    59. class expression
    60. delete operator
    61. function* 表达式
    62. in operator
    63. instanceof
    64. new operator
    65. new.target
    66. super
    67. this
    68. typeof
    69. void 运算符
    70. yield
    71. yield*
  10. 语句 & 声明
    1. async function
    2. block
    3. break
    4. class
    5. const
    6. continue
    7. debugger
    8. do...while
    9. empty
    10. export
    11. for
    12. for await...of
    13. for...in
    14. for...of
    15. 函数声明
    16. function*
    17. if...else
    18. import
    19. import.meta
    20. label
    21. let
    22. return
    23. switch
    24. throw
    25. try...catch
    26. var
    27. while
    28. with
  11. 函数
    1. 箭头函数表达式
    2. 默认参数
    3. 方法定义
    4. 其余参数
    5. 自变量对象
    6. getter
    7. setter
    1. Private class fields
    2. Public class fields
    3. 构造函数
    4. extends
    5. static
  12. 错误
    1. Error: Permission denied to access property "x"
    2. InternalError: too much recursion
    3. RangeError: argument is not a valid code point
    4. RangeError: invalid array length
    5. RangeError: invalid date
    6. RangeError: precision is out of range
    7. RangeError: radix must be an integer
    8. RangeError: repeat count must be less than infinity
    9. RangeError: repeat count must be non-negative
    10. ReferenceError: "x" is not defined
    11. ReferenceError: assignment to undeclared variable "x"
    12. ReferenceError: can't access lexical declaration`X' before initialization
    13. ReferenceError: deprecated caller or arguments usage
    14. ReferenceError: invalid assignment left-hand side
    15. ReferenceError: reference to undefined property "x"
    16. SyntaxError: "0"-prefixed octal literals and octal escape seq. are deprecated
    17. SyntaxError: "use strict" not allowed in function with non-simple parameters
    18. SyntaxError: "x" is a reserved identifier
    19. SyntaxError: JSON.parse: bad parsing
    20. SyntaxError: Malformed formal parameter
    21. SyntaxError: Unexpected token
    22. SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead
    23. SyntaxError: a declaration in the head of a for-of loop can't have an initializer
    24. SyntaxError: applying the 'delete' operator to an unqualified name is deprecated
    25. SyntaxError: for-in loop head declarations may not have initializers
    26. SyntaxError: function statement requires a name
    27. SyntaxError: identifier starts immediately after numeric literal
    28. SyntaxError: illegal character
    29. SyntaxError: invalid regular expression flag "x"
    30. SyntaxError: missing ) after argument list
    31. SyntaxError: missing ) after condition
    32. SyntaxError: missing : after property id
    33. SyntaxError: missing ; before statement
    34. SyntaxError: missing = in const declaration
    35. SyntaxError: missing ] after element list
    36. SyntaxError: missing formal parameter
    37. SyntaxError: missing name after . operator
    38. SyntaxError: missing variable name
    39. SyntaxError: missing } after function body
    40. SyntaxError: missing } after property list
    41. SyntaxError: redeclaration of formal parameter "x"
    42. SyntaxError: return not in function
    43. SyntaxError: test for equality (==) mistyped as assignment (=)?
    44. SyntaxError: unterminated string literal
    45. TypeError: "x" has no properties
    46. TypeError: "x" is (not) "y"
    47. TypeError: "x" is not a constructor
    48. TypeError: "x" is not a function
    49. TypeError: "x" is not a non-null object
    50. TypeError: "x" is read-only
    51. TypeError: 'x' is not iterable
    52. TypeError: More arguments needed
    53. TypeError: Reduce of empty array with no initial value
    54. TypeError: X.prototype.y called on incompatible type
    55. TypeError: can't access dead object
    56. TypeError: can't access property "x" of "y"
    57. TypeError: can't assign to property "x" on "y": not an object
    58. TypeError: can't define property "x": "obj" is not extensible
    59. TypeError: can't delete non-configurable array element
    60. TypeError: can't redefine non-configurable property "x"
    61. TypeError: cannot use 'in' operator to search for 'x' in 'y'
    62. TypeError: cyclic object value
    63. TypeError: invalid 'instanceof' operand 'x'
    64. TypeError: invalid Array.prototype.sort argument
    65. TypeError: invalid arguments
    66. TypeError: invalid assignment to const "x"
    67. TypeError: property "x" is non-configurable and can't be deleted
    68. TypeError: setting getter-only property "x"
    69. TypeError: variable "x" redeclares argument
    70. URIError: malformed URI sequence
    71. Warning: -file- is being assigned a //# sourceMappingURL, but already has one
    72. Warning: 08/09 is not a legal ECMA-262 octal constant
    73. Warning: Date.prototype.toLocaleFormat is deprecated
    74. Warning: JavaScript 1.6's for-each-in loops are deprecated
    75. Warning: String.x is deprecated; use String.prototype.x instead
    76. Warning: expression closures are deprecated
    77. Warning: unreachable code after return statement
  13. 杂项
    1. JavaScript technologies overview
    2. 词汇语法
    3. JavaScript 数据结构
    4. Enumerability and ownership of properties
    5. Iteration protocols
    6. 严格模式
    7. Transitioning to strict mode
    8. Template literals
    9. 弃用特征