Книга: Functional Programming in JavaScript
Назад: Function declarations versus function expressions versus the function constructor
Дальше: Function expressions

Function declarations

Function declarations, sometimes called function statements, define a function by using the keyword.

function foo(n) {   return n; }

Functions that are declared with this syntax are hoisted to the top of the current scope. What this actually means is that, even if the function is defined several lines down, JavaScript knows about it and can use it earlier in the scope. For example, the following will correctly print 6 to the console:

foo(2,3); function foo(n, m) {   console.log(n*m); }
Назад: Function declarations versus function expressions versus the function constructor
Дальше: Function expressions

bsn
thank
Vesa Karvonen
I hope you don't mind, but I’d like to point you and your readers to my high-performance optics library for JavaScript that is in production use in multiple projects, has comprehensive support for partial optics and interactive documentation: https://calmm-js.github.io/partial.lenses/ (this takes a moment to load — be patient!)