JavaScript Functions
<!DOCTYPE html> <html> <body> <h2>A function that remembers its surroundings</h2> <script> function makeGreeter(greeting) { // 'greeting' lives in the outer scope return function (name) { // The inner function still sees 'greeting' return greeting + ", " + name + "!"; }; } const sayHi = makeGreeter("Hi"); const sayHello = makeGreeter("Hello"); console.log(sayHi("Ada")); // "Hi, Ada!" console.log(sayHello("Grace")); // "Hello, Grace!" </script> </body> </html>