๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_functions.asp
JavaScript Function Study Path
A JavaScript callback is a function passed as an argument to another function, which is then executed (or "called back") at a later point in time to complete a specific task.
๐ŸŒ
Mozilla
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Guide โ€บ Functions
Functions - JavaScript - MDN Web Docs
A function in JavaScript is similar to a procedureโ€”a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ functions-in-javascript
Functions in JavaScript - GeeksforGeeks
Functions in JavaScript are reusable blocks of code designed to perform specific tasks. They allow you to organize, reuse, and modularize code.
Published ย  January 22, 2026
๐ŸŒ
javascript.com
javascript.com โ€บ learn โ€บ functions
Create Javascript functions with these free resources today
JavaScript functions are reusable blocks of code that perform a specific task, taking some form of input and returning an output.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_function_intro.asp
JavaScript Functions
Note that values returned from functions can be stored in variables. Variables declared within a JavaScript function, become LOCAL to the function.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Statements โ€บ function
function - JavaScript - MDN Web Docs - Mozilla
A function declaration creates a Function object. Each time when a function is called, it returns the value specified by the last executed return statement, or undefined if the end of the function body is reached.
๐ŸŒ
Eloquent JavaScript
eloquentjavascript.net โ€บ 03_functions.html
Functions :: Eloquent JavaScript
A function is created with an expression that starts with the keyword function. Functions have a set of parameters (in this case, only x) and a body, which contains the statements that are to be executed when the function is called.
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ javascript โ€บ javascript_functions.htm
JavaScript - Functions
A function in JavaScript is a group of reusable code that can be called anywhere in your program. It eliminates the need of writing the same code again and again. It helps programmers in writing modular codes.
๐ŸŒ
Programiz
programiz.com โ€บ javascript โ€บ function
JavaScript Function and Function Expressions (with Examples)
Become a certified JavaScript programmer. Try Programiz PRO! ... A function is an independent block of code that performs a specific task, while a function expression is a way to store functions in variables.
๐ŸŒ
web.dev
web.dev โ€บ learn โ€บ javascript โ€บ functions
Functions | web.dev
A function is a modular, reusable block of statements used to perform a set of related tasks, such as calculating and returning a value based on arguments provided to the function. As with all non-primitive values, functions are objects.
๐ŸŒ
JavaScript Tutorial
javascripttutorial.net โ€บ home โ€บ javascript tutorial โ€บ javascript functions
JavaScript Functions
November 15, 2024 - This tutorial introduces you to JavaScript functions that structure your code into smaller reusable units.
๐ŸŒ
Medium
calvincheng919.medium.com โ€บ what-are-javascript-functions-bbb9f0157de1
What are JavaScript Functions?. โ€ฆ and what are they good for? | by Calvin Cheng | Medium
June 30, 2021 - JavaScript functions are blocks of code you can call to perform a specific task. The basic structure is a function name (so you know what to call/execute later) and a function body where you insert code for what you want it to do.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ what-are-functions-in-javascript-a-beginners-guide
What are Functions in JavaScript? A Beginner's Guide
June 30, 2022 - You can think of a function as a sub-program within the main program. A function consists of a set of statements but executes as a single unit. In JavaScript, we have some browser built-in functions like alert(), prompt(), and confirm(). You ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ understanding-functions-in-javascript
How Functions Work in JavaScript โ€“ JS Function Code Examples
January 20, 2023 - The function multiplies the number by 2 and then invokes the callback function, passing the result as an argument. The logResult function is then executed, which logs the result to the console. JavaScript functions also have a feature called default parameters.
Top answer
1 of 3
236

It's a Generator function.

Generators are functions which can be exited and later re-entered. Their context (variable bindings) will be saved across re-entrances.

Calling a generator function does not execute its body immediately; an iterator object for the function is returned instead. When the iterator's next() method is called, the generator function's body is executed until the first yield expression, which specifies the value to be returned from the iterator or, with yield*, delegates to another generator function.


Historical note:

It's a proposed syntax for EcmaScript.next.

Dave Herman of Mozilla gave a talk about EcmaScript.next. At 30:15 he talks about generators.

Earlier, he explains how Mozilla is experimentally implementing proposed language changes to help steer the committee. Dave works closely with Brendan Eich, Mozilla's CTO (I think), and the original JavaScript designer.

You can find more detail on the EcmaScript working group wiki: http://wiki.ecmascript.org/doku.php?id=harmony:generators

The working group (TC-39) has general agreement that EcmaScript.next should have some kind of generator iterator proposal, but this is not final.

You shouldn't rely on this showing up without changes in the next version of the language, and even if it doesn't change, it probably won't show up widely in other browsers for a while.

Overview

First-class coroutines, represented as objects encapsulating suspended execution contexts (i.e., function activations). Prior art: Python, Icon, Lua, Scheme, Smalltalk.

Examples

The โ€œinfiniteโ€ sequence of Fibonacci numbers (notwithstanding behavior around 253):

function* fibonacci() {
    let [prev, curr] = [0, 1];
    for (;;) {
        [prev, curr] = [curr, prev + curr];
        yield curr;
    }
}

Generators can be iterated over in loops:

for (n of fibonacci()) {
    // truncate the sequence at 1000
    if (n > 1000)
        break;
    print(n);
}

Generators are iterators:

let seq = fibonacci();
print(seq.next()); // 1
print(seq.next()); // 2
print(seq.next()); // 3
print(seq.next()); // 5
print(seq.next()); // 8
2 of 3
57

It's a generator function - and it said so in the page you cite, in the comment you replaced with "this is the interesting line"...

Basically it's a way to specify sequences programmatically so that they can be passed around and elements accessed by index without having to compute the entire sequence (possibly infinite in size) beforehand.