Create Strings using Template Literals - Issue with const declaration declaration

Create Strings using Template Literals - Issue with const declaration declaration
0

#1

Tell us what’s happening:
I handed the challenge but I’m troubled by this.
How come I can declare a const resultDisplayArray within the function makeList and then reassign to const resultDisplayArray a value that is makeList(result.failure).

My trouble comes from fact that we’re resultDisplayArray within and outside the function. Is that because the scope of the const is limited to the function where it’s declared, meaning that resultDisplayArray inside makeList and outside makeList is actually not the same?

I’m really confused and feel like I’ve missed something important in the learning process. If anyone has some suggestion for good resources to better understand it, that would be tremendous!

Peace

Your code so far


const result = {
  success: ["max-length", "no-amd", "prefer-arrow-functions"],
  failure: ["no-var", "var-on-top", "linebreak"],
  skipped: ["id-blacklist", "no-dup-keys"]
};
function makeList(arr) {
  "use strict";

  // change code below this line
const resultDisplayArray = arr.map(x => `<li class="text-warning">${x}</li>`);
  // change code above this line

  return resultDisplayArray;
}
/**
 * makeList(result.failure) should return:
 * [ `<li class="text-warning">no-var</li>`,
 *   `<li class="text-warning">var-on-top</li>`, 
 *   `<li class="text-warning">linebreak</li>` ]
 **/
const resultDisplayArray = makeList(result.failure);
console.log(resultDisplayArray);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/create-strings-using-template-literals


#2

It’s in the function, so it’s a different scope; the resultDisplayArray inside is not the same as the one outside (it is confusing giving them the same name).