Skip to content

Instantly share code, notes, and snippets.

@dianjuar
Last active January 4, 2022 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dianjuar/9688caa32f8023e9ed9bf2aabfe896ec to your computer and use it in GitHub Desktop.
Save dianjuar/9688caa32f8023e9ed9bf2aabfe896ec to your computer and use it in GitHub Desktop.
JS Interview Questions Snipets

What would be the output of these?

1

function() {
  this.foo = 'bar';
  const dummyFn = () => this.foo;

  console.log(dummyFn());
}

2

function() {
  this.foo = 'bar';
  const dummyFn = function() { return this.foo };

  console.log(dummyFn());
}

Hoisting

1

console.log(foo);
var foo = 'bar';

2

console.log(foo);
let foo = 'bar';

Is this a pura function?

let foo = 'bar';

function dummyFn() {
  foo = '---';
}

Design-wise, what's wrong with this function

const fruitArr = ["๐Ÿ‡", "๐Ÿˆ", "๐Ÿ‰", "๐ŸŠ", "๐Ÿ‹"];

const getRandomElementFromArray = function (paramArr) {
  const randomNumber = Math.floor(Math.random() * paramArr.length);
  return fruitArr[randomNumber];
};

const randomEl = getRandomElementFromArray(fruitArr);
console.log(randomEl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment