DEV Community

cienc
cienc

Posted on

[Javascript]

Setting up

Jest

npm install -g jest
npm root -g

# Run test
jest test.js --watch
Enter fullscreen mode Exit fullscreen mode

debugger

function funcName() {
  //  
  debugger;
  //
}
Enter fullscreen mode Exit fullscreen mode
node inspect test.js

# continue
debug> c

# enter repl to check the variables
debug> repl

Enter fullscreen mode Exit fullscreen mode

Null vs Undefined

let test;
console.log( test ); // undefined

test = null
console.log( test ); // null

console.log( 1 + null ); // 1
console.log( 1 + undefined ); // NaN

console.log( null == undefined ); // true
console.log( null === undefined ); // false
Enter fullscreen mode Exit fullscreen mode

Reverse String

function reverse(str) {
}
Enter fullscreen mode Exit fullscreen mode

Memoization - Fibonacci

function memoize(fn) {
  const cache = {};
  return function (...args) {
    if (cache[args]) {
      return cache[args];
    }

    const result = fn.apply(this, args);
    cache[args] = result;

    return result;
  };
}

function slowFib(n) {
  if (n <= 1) return n;

  return fib(n - 1) + fib(n - 2);
}

const fib = memoize(slowFib);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)