Search code examples
javascriptfunctiond3.jsobservablehq

In Javascript, what does ƒ mean?


I've seen this ƒ symbol (an italics f with an undertail, if you can't see it properly), for example: here: https://observablehq.com/@d3/zoomable-sunburst

He uses it with the following code, but I'm not sure what purpose it serves:

color = ƒ(i)    
color = d3.scaleOrdinal(d3.quantize(d3.interpolateRainbow, data.children.length + 1))

What is the purpose of this?

Thank you!


Solution

  • An Observable cell contains two main components: the output goes in the white area above (next to the three dots), while the code goes in the gray area just below it (next to the pin). What you're seeing is just the output of the cell, and that ƒ is the way the Observable team chose to indicate a function.

    For instance, have a look at this function:

    enter image description here

    As you can see, the output is just the function itself, not it's returned value. But if we call it:

    enter image description here

    Finally, if we pass a value:

    enter image description here

    Also related to your question, pay attention to the title of this introductory page, which I'll reproduce in bold: Observable is not JavaScript. It's a bit exaggerated (the language used is JavaScript), but the author intent is to show that Observable has a lot of syntax peculiarities.