Skip to content

Commit d9c2904

Browse files
author
James Allardice
committed
Add note about function declaration hoisting
1 parent 62ba631 commit d9c2904

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

message-articles/not-defined.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ scope in which it should be available:
134134
var x = 10;
135135
```
136136

137+
If you understand the concept of hoisting and prefer to define functions after
138+
they are used (perhaps at the end of a file) you can tell JSHint to allow that
139+
specific use case by setting the `latedef` option to `nofunc`:
140+
141+
<!---
142+
{
143+
"linter": "jshint"
144+
}
145+
-->
146+
```javascript
147+
/*jshint latedef: nofunc */
148+
doStuff();
149+
150+
function doStuff() {
151+
return 1;
152+
}
153+
```
154+
137155
In the case of environment-specific global identifiers (like `window` or
138156
`document` in the browser or `module` in Node.js) there are a few JSLint/JSHint
139157
options that you can set to let the linter know what environment the code is

0 commit comments

Comments
 (0)