-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
80 lines (60 loc) · 1.64 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
title: "SyntaxError: missing } after function body"
slug: Web/JavaScript/Reference/Errors/Missing_curly_after_function_body
page-type: javascript-error
---
{{jsSidebar("Errors")}}
The JavaScript exception "missing } after function body" occurs when there is a syntax
mistake when creating a function somewhere. Check if any closing curly braces or
parenthesis are in the correct order.
## Message
```plain
SyntaxError: missing } after function body (Firefox)
```
## Error type
{{jsxref("SyntaxError")}}
## What went wrong?
There is a syntax mistake when creating a function somewhere. Also check if any closing
curly braces or parenthesis are in the correct order. Indenting or formatting the code
a bit nicer might also help you to see through the jungle.
## Examples
### Forgotten closing curly bracket
Oftentimes, there is a missing curly bracket in your function code:
```js-nolint example-bad
function charge() {
if (sunny) {
useSolarCells();
} else {
promptBikeRide();
}
```
Correct would be:
```js example-good
function charge() {
if (sunny) {
useSolarCells();
} else {
promptBikeRide();
}
}
```
It can be more obscure when using [IIFEs](/en-US/docs/Glossary/IIFE) or other constructs that use
a lot of different parenthesis and curly braces, for example.
```js-nolint example-bad
(function () {
if (Math.random() < 0.01) {
doSomething();
}
)();
```
Oftentimes, indenting differently or double checking indentation helps to spot these
errors.
```js example-good
(function () {
if (Math.random() < 0.01) {
doSomething();
}
})();
```
## See also
- [Functions](/en-US/docs/Web/JavaScript/Guide/Functions) guide