Search notes:

JavaScript: closure

function createClosure(arg_1, arg_2) {

   var txtVar = 'txt (var)';
   let txtLet = 'txt (let)';

   function func() {
      console.log('txtVar = ' + txtVar);
      console.log('txtLet = ' + txtLet);
      console.log('arg_1  = ' + arg_1 );
      console.log('arg_2  = ' + arg_2 );
   }

   txtVar = 'txt (var) has changed';
   txtLet = 'txt (let) has changed';

   return func;
}

function main() {

   var a1 = 'one';
   let a2 = 'two';

   var f1 = createClosure(a1, a2);

   a1 = 'ONE';
   a2 = 'TWO';

   var f2 = createClosure(a1, a2);

   f1();
   console.log('----');
   f2();

}

main();
Github repository about-javascript, path: /function/closure/ex-01.js
The code above prints
txtVar = txt (var) has changed
txtLet = txt (let) has changed
arg_1  = one
arg_2  = two
----
txtVar = txt (var) has changed
txtLet = txt (let) has changed
arg_1  = ONE
arg_2  = TWO

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759561894, '216.73.216.149', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/JavaScript/function/closure/index(81): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78