Flashcards

IIFE Flash Cards

1. When is an IIFE invoked?

2. True or False: A single IIFE can be invoked multiple times throughout an application.

3. What does IIFE stand for?

4. What is is the value of the test variable when the below code is run?

const test = (function () {
  return "hello";
})();

console.log(test); // ???

5. What will happen when the below function is run?

(function () {
  const test = "Hello world!";
})();

console.log(test); // ???

6. It is best practice to write an IIFE as what kind of function?

7. How can IIFEs help to keep the global namespace from being polluted by variables that are only used once?


Hoisting in Javascript Flash Cards

1. Which way of defining a new function will hoist the name of the function to the top of it’s current scope?

2. What will happen when the below code snippet is run?

meFunction();

function meFunction() {
  console.log("hello!");
}

3. What will happen when the below function is invoked?

hello();

let hello = function () {
  console.log("hello!");
};

4. What will be printed when the below function is run?

let party = "pineapple";

function party(num) {
  console.log("party time!");
}

console.log(party);

5. What will happen when the below code snippet is run?

var foo = "apple";

function foo(num) {
  return "banana";
}

console.log(foo);

6. What will happen when the below code snippet is run?

var foo;

function foo(num) {
  return "I'm a function";
}

console.log(foo);

Falsey Values in JavaScript

1. Is an empty string, (""), a truthy or falsey value in JS?

2. Name the seven falsey values in JavaScript.

3. Is (“false”) truthy or falsey in JavaScript?

4. Is an empty object, ({}), truthy or falsey in JavaScript?

5. Is an empy array, ([]), truthy or falsey in JavaScript?

6. Is 0 truthy or falsey in JavaScript?

7. What will be printed to the console when the below code is run?

if (NaN || 0 || "" || null || undefined) {
  console.log("hello");
} else {
  console.log("goodbye");
}

8. What will be printed when the below code is run?

if (0 || "" || "0") {
  console.log("hello");
} else {
  console.log("goodbye");
}