Zhen Zhang


Eloquent JS: Functions

June 13, 2026

1.A return keyword without an expression after it will cause the function to return undefined.

2.So old-style binding, created with var keyword are visiable throughout the whole function in which they appear --or throughout the global scope if they are not in a function.

3.console.log("The future says:", future() ); function future() { return "You'll never have flying cars." }

4.The preceding code works, even though the function is defined below the code that use it.

5.The feature - being able to reference a specific instance of local binding in an eclosing scope - is called closure. A function that references binding from local scopes around it is called a closure.

6.When called, the function body sees the enviroment in which it was created not the enviroment in which it is called.

7.A useful principle is to refrain from adding cleverness unless you are absolutely sure you're going to need it. It can be tempting to write general "framework" for every bit of functionlity you come across. Resist that urge. You won't got any real work done -- You'll be too busy writing code that you never use.

8.A pure funciton is a specific kind of value-producing fucntion that not only has no side effects but also doesn't rely on side effects from other code -- for example, it doesn't read global binding whose value might change. A pure function has the pleasant property that when called with the same arguments, it always produces the same value(and doesn't do anything else).

9.

function findSolution(target){
  function find(current, history) {
    if(current == target) {
      return history;
    } else if (current > target){
      return null;
    } else {
      return find(current + 5,`(${history}+5)`)??
             find(current * 3, `(${history}*3)`)
    }
  } 
  return find(1, "1");
}


About Privacy Home