The value of a constant cannot change through re-assignment

The value of a constant cannot change through re-assignment
0

#1

Tell us what’s happening:

Hello Campers!
So const cannot change through re-assignment, but why here

 const teaCups = [];
  
  for(let cups = 1; cups <= numOfCups; cups += 1) {
    const teaCups = prepareTea();
    teaCups.push(teaCup);
  }

why does const teaCups’ value change? Can someone explain it to me?
it is because the const teaCups in the loop in not related with the const outside?
and also teaCup is not defined with let or const but it exists as argument. I don’t understand this part can you help me??

Your code so far


/**
 * A long process to prepare tea.
 * @return {string} A cup of tea.
 **/
const prepareTea = () => 'greenTea';

/**
 * Get given number of cups of tea.
 * @param {number} numOfCups Number of required cups of tea.
 * @return {Array<string>} Given amount of tea cups.
 **/
const getTea = (numOfCups) => {
  const teaCups = [];
  
  for(let cups = 1; cups <= numOfCups; cups += 1) {
    const teaCups = prepareTea();
    teaCups.push(teaCup);
  }

  return teaCups;
};

// Add your code below this line

const tea4TeamFCC = getTea(40); // :(

// Add your code above this line

console.log(tea4TeamFCC);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/learn-about-functional-programming


#2

const is block scoped, anything within curly braces is a block. So a variable declared in a block with const or let is only available for use within that block.


#3

Thank you! I see where I was wrong.