DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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)

Need a better mental model for async/await?

Check out this classic DEV post on the subject.

β­οΈπŸŽ€ JavaScript Visualized: Promises & Async/Await

async await